Skip to content

Commit

Permalink
Changed folder layout
Browse files Browse the repository at this point in the history
  • Loading branch information
rkdan committed Jun 14, 2024
1 parent 5e69761 commit c0d2fea
Show file tree
Hide file tree
Showing 19 changed files with 76 additions and 25 deletions.
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
/venv
docs/.DS_Store
diffusion-models/notebooks/mnist_data/
diffusion-models/notebooks/ecg/
diffusion-models/mnist_data
diffusion-models/__pycache__
/notebooks/data/

13 changes: 0 additions & 13 deletions diffusion-models/CLIP.py

This file was deleted.

File renamed without changes.
57 changes: 57 additions & 0 deletions diffusion-models/clip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import torch
import torch.nn as nn
import numpy as np


class DigitEncoder(nn.Module):
def __init__(self):
super().__init__()
self.encoder = torch.nn.Sequential(
nn.Linear(28*28, 256),
nn.ReLU(),
nn.Linear(256, 128),
nn.ReLU(),
nn.Linear(128, 32)
)

def forward(self, x):
return self.encoder(x)


class LabelEncoder(nn.Module):
def __init__(self):
super().__init__()
self.encoder = nn.Sequential(
nn.Linear(10, 16),
nn.ReLU(),
nn.Linear(16, 32)
)

def forward(self, x):
return self.encoder(x)


class BasicCLIP(nn.Module):
def __init__(self):
super().__init__(latent_dim=32)

self.image_encoder = DigitEncoder()
self.label_encoder = LabelEncoder()
self.temperature = nn.Parameter(torch.tensor(np.log(1/0.07)))

self.W_i = nn.Linear(32, 128)
self.W_t = nn.Linear(32, 128)

def forward(self, imgs, labels):
I_f = self.image_encoder(imgs)
T_f = self.label_encoder(labels)

I_e = self.W_i(I_f)
T_e = self.W_t(T_f)

I_e = torch.nn.functional.normalize(I_e, p=2, dim=1)
T_e = torch.nn.functional.normalize(T_e, p=2, dim=1)

logits = I_e @ T_e.T * self.temperature

return logits
Binary file removed diffusion-models/model_bigger.pth
Binary file not shown.
6 changes: 0 additions & 6 deletions diffusion-models/requirements.txt

This file was deleted.

File renamed without changes.
Empty file added diffusion-models/vae.py
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,17 @@
},
"metadata": {},
"output_type": "display_data"
},
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mThe Kernel crashed while executing code in the current cell or a previous cell. \n",
"\u001b[1;31mPlease review the code in the cell(s) to identify a possible cause of the failure. \n",
"\u001b[1;31mClick <a href='https://aka.ms/vscodeJupyterKernelCrash'>here</a> for more info. \n",
"\u001b[1;31mView Jupyter <a href='command:jupyter.viewOutput'>log</a> for further details."
]
}
],
"source": [
Expand Down
File renamed without changes.
8 changes: 6 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
mkdocstrings==0.25.1
mkdocs-material==9.5.21
torch==2.3.0
torchvision==0.18.0
matplotlib==3.9.0
seaborn==0.13.2
diffusers==0.28.2
transformers==4.41.2
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit c0d2fea

Please sign in to comment.