Representation Learning with Contrastive Predictive Coding (CPC)
논문 읽기 연습/그냥 메모

Representation Learning with Contrastive Predictive Coding (CPC)

https://www.youtube.com/watch?v=X4fwPhGaR8Q&ab_channel=%EA%B3%A0%EB%A0%A4%EB%8C%80%ED%95%99%EA%B5%90%EC%82%B0%EC%97%85%EA%B2%BD%EC%98%81%EA%B3%B5%ED%95%99%EB%B6%80DSBA%EC%97%B0%EA%B5%AC%EC%8B%A4 

밑은 CNN이든 뭐든 어쨌든 latent vector를 만들고 위는 GRU, LSTM등의 시계열로 처리해서 관계성. 나중엔 여기에 내 목적용 classification 용 layer만 붙여 fine tuning해서 사용.

 

 

밑은 다른 코드에서 cpc를 작성한거 분석한것.

https://github.com/hhi-aml/ecg-selfsupervised/blob/main/clinical_ts/cpc.py

 

GitHub - hhi-aml/ecg-selfsupervised: Self-supervised representation learning from 12-lead ECG data

Self-supervised representation learning from 12-lead ECG data - GitHub - hhi-aml/ecg-selfsupervised: Self-supervised representation learning from 12-lead ECG data

github.com

 

 

 

 

밑에건 finetuning 부분.

#copied from RNN1d
class AdaptiveConcatPoolRNN(nn.Module):
    def __init__(self, bidirectional=False):
        super().__init__()
        self.bidirectional = bidirectional
    def forward(self,x):
        #input shape bs, ch, ts
        t1 = nn.AdaptiveAvgPool1d(1)(x)
        t2 = nn.AdaptiveMaxPool1d(1)(x)

        if(self.bidirectional is False):
            t3 = x[:,:,-1]
        else:
            channels = x.size()[1]
            t3 = torch.cat([x[:,:channels,-1],x[:,channels:,0]],1)
        out=torch.cat([t1.squeeze(-1),t2.squeeze(-1),t3],1) #output shape bs, 3*ch
        return out