Giter VIP home page Giter VIP logo

cryo-em-denoising-pytorch-v1's Introduction

cryo-EM-denoising-pytorch-v1

Principle

Background Info

Cryo-electron microscopy has gradually become an important technology in the field of structural biology. With the development and improvement of hardware and software, more and more molecular biological structures close to atomic resolution have been resolved. In order to obtain an accurate and reliable three-dimensional structure, it is a very important and critical step to perform cluster analysis on the projection images of cryo-electron microscopy.

Siamese Network

  1. Randomly choose two images from the dataset, in one cluster or not.

  2. Send two images into the same networks (feature extractor), and obtain two latent vectors.

  3. Use the Contrastive Loss Function to evaluate the dissimilarity between two images.

$$L = \frac{1}{2N}\sum_{n=1}^N(1-y)d^2+(y)\max(\text{margin}-d,0)^2$$

y = 1 stands for the two images that come from different clusters, y = 0 stands for the two images that come from the same clusters.

  1. Kmeans are used to assign new labels.
# Siamese Network
class SiameseNetwork(nn.Module):
    def __init__(self):
        super().__init__()
        self.cnn1 = nn.Sequential(
            nn.ReflectionPad2d(1),
            nn.Conv2d(1,4,kernel_size=3),
            nn.ReLU(inplace=True),
            nn.BatchNorm2d(4),

            nn.ReflectionPad2d(1),
            nn.Conv2d(4,8,kernel_size=3),
            nn.ReLU(inplace=True),
            nn.BatchNorm2d(8),

            nn.ReflectionPad2d(1),
            nn.Conv2d(8,8,kernel_size=3),
            nn.ReLU(inplace=True),
            nn.BatchNorm2d(8),
        )

        self.fc1 = nn.Sequential(
            nn.Linear(8*64*64,500),
            nn.ReLU(inplace=True),

            nn.Linear(500,100),
            nn.ReLU(inplace=True),

            nn.Linear(100,20)
        )

    def forward_once(self,x):
        output = self.cnn1(x)
        output = output.view(output.size()[0],-1)
        output = self.fc1(output)
        return output

    def forward(self,input1,input2):
        output1 = self.forward_once(input1)
        output2 = self.forward_once(input2)
        return output1, output2 
        
# ContrastiveLoss Function
class ContrastiveLoss(torch.nn.Module):
    def __init__(self,margin=2):
        super(ContrastiveLoss, self).__init__()
        self.margin = margin
  
    def forward(self,output1,output2,label):
        euclidean_distance = F.pairwise_distance(output1,output2,keepdim=True)
        loss_constrastive = torch.mean((1-label)*torch.pow(euclidean_distance,2)+
                        (label)*torch.pow(torch.clamp(self.margin-euclidean_distance,min=0.0),2))
        return loss_constrastive

Result

Loss

loss

Clustering

cluster

Denoising Result

average

Usage

pip install -r requirements.txt

python main.py -h
usage: main.py [-h] [-c CLUSTER_NUM] [-g GPU] [-l LEARNING_RATE]
               [-e EPOCH_NUM] [-b BATCH_SIZE] [-r ROUND_NUM] [-d DATASET_DIR]

Cryo-EM Images Denoising v1

optional arguments:
  -h, --help            show this help message and exit
  -c CLUSTER_NUM, --cluster_num CLUSTER_NUM
  -g GPU, --gpu GPU
  -l LEARNING_RATE, --learning_rate LEARNING_RATE
  -e EPOCH_NUM, --epoch_num EPOCH_NUM
  -b BATCH_SIZE, --batch_size BATCH_SIZE
  -r ROUND_NUM, --round_num ROUND_NUM
  -d DATASET_DIR, --dataset_dir DATASET_DIR

cryo-em-denoising-pytorch-v1's People

Contributors

zhangyumeng1sjtu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Forkers

jjjjjasonzheng

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.