Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static dev #3

Open
wants to merge 138 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
138 commits
Select commit Hold shift + click to select a range
bbd10c1
first commit of dataset for non-time
mat10d Aug 30, 2024
01cc47b
moved dataset static to src
mat10d Aug 30, 2024
3d22b75
added dataloader
mat10d Aug 30, 2024
3edf003
tested static dataset
mat10d Aug 30, 2024
6a5fca1
add pyproject commit
mat10d Aug 30, 2024
cb99bc1
added data split code
mat10d Aug 30, 2024
76349cd
example vae mnist
Aug 30, 2024
f3418d5
finalized dataloader/splitter for static data
mat10d Aug 30, 2024
3b893dd
added dataloader for static
mat10d Aug 31, 2024
70c076a
Update README.md
ijan780 Aug 29, 2024
fb57eca
Add black linter
adjavon Aug 30, 2024
2b30da6
Add dev setup
adjavon Aug 31, 2024
e518d29
Add dummy model
adjavon Aug 31, 2024
5583578
Add VAE tests
adjavon Aug 31, 2024
cc62e47
Add test CI
adjavon Aug 31, 2024
e6c0f49
Add black linter
adjavon Aug 30, 2024
71007aa
fix pyproject
mat10d Aug 31, 2024
0dabae3
Add dummy model
adjavon Aug 31, 2024
1f5d0cc
Add VAE tests
adjavon Aug 31, 2024
9865435
Add test CI
adjavon Aug 31, 2024
70659a4
new training test notebook
mat10d Aug 31, 2024
d9ea4b1
notebooks with code to read neuromast dataset
akila-14 Aug 31, 2024
aeb9a6c
Merge branch 'static_dev' into Akila
akila-14 Aug 31, 2024
5553fbd
first training loop!
mat10d Aug 31, 2024
b6dbe4a
Merge branch 'static_dev' into Akila
akila-14 Aug 31, 2024
7cabe65
overnight changes (minimal)
mat10d Aug 31, 2024
dac03c5
cleaned datasets (temp)
mat10d Aug 31, 2024
9330d2a
preliminary normalization
mat10d Aug 31, 2024
4a48864
commit to save files
akila-14 Aug 31, 2024
d7c59d0
commit to save
akila-14 Aug 31, 2024
a70c677
pre training
Alecampoy Aug 31, 2024
97b5327
overnight changes (minimal)
mat10d Aug 31, 2024
0ab9aa8
training loop.py
Alecampoy Aug 31, 2024
16bfd53
test
Alecampoy Aug 31, 2024
6ab7cb1
Add dev setup
adjavon Aug 31, 2024
124c5e3
Added dataloader for live-TLS dataset and Notebook to check functiona…
Aug 30, 2024
405a7d6
Added notebook entries to test normalization, added those functions t…
Aug 30, 2024
3f6c7e0
Fixed dependencies.
ijan780 Aug 30, 2024
d827e85
Added dependencies.
ijan780 Aug 30, 2024
05d648a
added custom transform for selecting timepoint and added notebook for…
Aug 30, 2024
2e755d4
Confirmed SelectRandomTimepoint Transform in notebook
Aug 30, 2024
58d4d54
Added UNet based Autoencoder
Aug 31, 2024
346c27d
adding notebook changes and small space diffs
Aug 31, 2024
156ddfa
WPI: decoder.
ijan780 Aug 31, 2024
3dc0e60
Add dev setup
adjavon Aug 31, 2024
c7de5a9
Added dataloader for live-TLS dataset and Notebook to check functiona…
Aug 30, 2024
e6bdf3a
Fixed dependencies.
ijan780 Aug 30, 2024
a084af0
added notebook for splitting into train test set
Aug 31, 2024
11740fc
Remove annoying file (finally)
ijan780 Aug 31, 2024
7c69c61
Added train & Ian's data loader (WPI)
ijan780 Aug 31, 2024
f443fe0
added unet based decoder code still unfinished, implemented first tra…
Aug 31, 2024
a018a65
add final convolution to decoder
Aug 31, 2024
b47dde1
Renamed encoder decoder code to something more useful
Aug 31, 2024
5a693f8
renaming dataloader
Aug 31, 2024
81bdfd6
added folder to scripts to discriminate our work on main
Aug 31, 2024
8fcf005
added unsaved changes in train loop
Aug 31, 2024
4058b4e
notebooks with code to read neuromast dataset
akila-14 Aug 31, 2024
508f875
add pyproject commit
mat10d Aug 30, 2024
e18e79e
fix pyproject
mat10d Aug 31, 2024
7059180
fix pyproject.toml
mat10d Aug 31, 2024
df8a5f2
commit to save files
akila-14 Aug 31, 2024
ab50c99
fixing some rebase errors
akila-14 Aug 31, 2024
09be91a
fixed bug in static
mat10d Aug 31, 2024
3f93956
final normalization push
mat10d Sep 1, 2024
c0ff440
pre training
Alecampoy Aug 31, 2024
17ada70
training loop.py
Alecampoy Aug 31, 2024
c19faaf
test
Alecampoy Aug 31, 2024
e097e93
cleaned datasets (temp)
mat10d Aug 31, 2024
3ec5bc7
final normalization push
mat10d Sep 1, 2024
94cabea
version to keep
mat10d Sep 1, 2024
385b70f
Revert "final normalization push"
mat10d Sep 1, 2024
9ffe213
add the script dataset_static
mat10d Sep 1, 2024
501b114
remove notebooks
mat10d Sep 1, 2024
655b109
training loop with embeddings in tensor board
akila-14 Sep 1, 2024
5062ccc
updated training loop with checkpoints
akila-14 Sep 1, 2024
1b5fb70
added cropping for images
Aug 31, 2024
992162a
rename first training script
Aug 31, 2024
2c19d86
make second train loop and rename UNet encoder name
Aug 31, 2024
1adff03
removed print statements and fixed bug in decoder training loop of fi…
Aug 31, 2024
6f1ae03
Created model dictionary
ijan780 Aug 31, 2024
1c5987c
added notebook to check model outs
Aug 31, 2024
eeae1d7
added notebook to explore resnet encoder
Sep 1, 2024
fd1611f
first test with simclr
afoix Aug 31, 2024
9bbca88
first serve of the dataloader
afoix Aug 31, 2024
64c2047
working state dataloader
afoix Aug 31, 2024
d7511df
VAE_resnet18 model to test
afoix Aug 31, 2024
81274bc
fix VAEResnet
afoix Sep 1, 2024
7f78430
no bugs, yet to train
Ben-Salmon Sep 1, 2024
f2896bd
remove in place operations
Ben-Salmon Sep 1, 2024
4cadf68
new training on resnet
Alecampoy Sep 1, 2024
27cab32
added resnet taining loop and resnet test notebook
akila-14 Sep 1, 2024
7524ad7
cleanup of dataset, sunday
mat10d Sep 1, 2024
d598a87
new trainintg loop
Alecampoy Sep 1, 2024
9bae23a
new training on resnet
Alecampoy Sep 1, 2024
6a9eb6a
new trainintg loop
Alecampoy Sep 1, 2024
903dd2a
Merge branch 'Ale_training' into Akila
adjavon Sep 1, 2024
69257a0
Redo Ale's updates
adjavon Sep 1, 2024
783e37e
Merge branch 'static_dev' into Akila
adjavon Sep 1, 2024
054483f
Merge pull request #4 from Cryaaa/Akila
adjavon Sep 1, 2024
b295299
fixed training loop with new dataset
mat10d Sep 1, 2024
4d2df4e
black
Alecampoy Sep 1, 2024
e15bdcd
changes in git ignore
Alecampoy Sep 2, 2024
08cf431
pre training ResVae
Alecampoy Sep 2, 2024
92be390
added training loops for md, modified static dataloader
mat10d Sep 2, 2024
af464cf
updated training loops to split loss, use small dataset
mat10d Sep 2, 2024
fefe44b
updated training loops for logging
mat10d Sep 2, 2024
95a90aa
speed up data loader in training loops
mat10d Sep 2, 2024
a75f70d
add evaluation
mat10d Sep 2, 2024
92f36bb
linear model AC
Alecampoy Sep 2, 2024
f5485c5
Fix errors incurred during rebase
Alecampoy Sep 2, 2024
360922a
Return linear ac model to original state
Alecampoy Sep 2, 2024
8026281
ok linear ac model
Alecampoy Sep 2, 2024
4098ce9
add sampling for evaluation
mat10d Sep 2, 2024
486a2cd
adding print model and zarr dataloader
Alecampoy Sep 3, 2024
c76be50
add changes to min normalizing
mat10d Sep 3, 2024
29a90b0
Merge branch 'static_dev' of github.com:Cryaaa/embed_time into static…
Alecampoy Sep 3, 2024
85430e2
bug fixes for linear model evaluation
mat10d Sep 3, 2024
6f05288
Add non-targeting experiments
adjavon Sep 3, 2024
a24c559
zarr dataloader mitocondria
Alecampoy Sep 3, 2024
0e987ca
pyproject.toml update
akila-14 Sep 1, 2024
ba3ee67
neuromast dataset notebook with centroids
akila-14 Sep 1, 2024
993bb9a
removed a script
akila-14 Sep 1, 2024
43b4058
modified training loop and added neuromast metadat scripts
akila-14 Sep 3, 2024
65be0a1
training loop for neuromast 2D
akila-14 Sep 3, 2024
2b7e88f
neuromast validation script and dataset class
akila-14 Sep 3, 2024
c43fca6
added test notebook
akila-14 Sep 3, 2024
3696e15
evaluation neuromast
akila-14 Sep 3, 2024
79469cb
evaluation improvements, maybe lost the resnet script
mat10d Sep 4, 2024
285efe3
updated evaluation
mat10d Sep 4, 2024
0daed58
Add benchmark dataset creation
adjavon Sep 4, 2024
8739de5
neuromast class
akila-14 Sep 4, 2024
3cc0eae
evaluation, classifier
akila-14 Sep 4, 2024
28e2634
Add visualization
adjavon Sep 4, 2024
6c03315
matteo final commit :/
mat10d Sep 7, 2024
956e338
fixed error in toml file to hopefully fix tests
Cryaaa Sep 10, 2024
43896f1
wasn't quite there yet
Cryaaa Sep 10, 2024
bfedf85
fixed all the duplicate dependancies and misnamed libraries
Cryaaa Sep 10, 2024
5d55f83
get rid of duplicate dependancies in in dev
Cryaaa Sep 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/black.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Python Black

on: [push, pull_request]

jobs:
lint:
name: Python Lint
runs-on: ubuntu-latest
steps:
- name: Setup Python
uses: actions/setup-python@v5
- name: Setup checkout
uses: actions/checkout@master
- name: Lint with Black
run: |
pip install black
black --diff --check src/embed_time
28 changes: 28 additions & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Test

on:
push:

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10"]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install ".[dev]"
- name: Test with pytest
run: |
pytest --color=yes
# Coverage should work out of the box for public repos. For private repos, more setup is likely required.
- name: Coverage
uses: codecov/codecov-action@v4
13 changes: 12 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
*.zarr
*.tiff
*.tif
**/data/
**/mnist_data/
**/data/
**/mnist_data/
/notebooks/splits
/scripts/embed_time_runs
/scripts/graphs

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down Expand Up @@ -126,4 +133,8 @@ pyrepo
.vscode/

# OS Files
.DS_Store
.DS_Store

#logs
embed_time_runs/
embed_time_static_runs/
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
Create a new environment
```bash
conda create -n embed_time python=3.10
conda activate 3.10
conda activate embed_time
pip install -e .
conda install -y pytorch-gpu cuda-toolkit=11.8 torchvision -c nvidia -c conda-forge -c pytorch

```
188 changes: 188 additions & 0 deletions backup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
import torch
from torch import nn, optim
import torch.nn.functional as F
import numpy as np

class ResizeConv2d(nn.Module):
def __init__(self, in_channels, out_channels, kernel_size, scale_factor, mode='nearest'):
super().__init__()
self.scale_factor = scale_factor
self.mode = mode
self.conv = nn.Conv2d(in_channels, out_channels, kernel_size, stride=1, padding=kernel_size//2)
def forward(self, x):
x = F.interpolate(x, scale_factor=self.scale_factor, mode=self.mode)
x = self.conv(x)
return x

class ResizeArbitrary(nn.Module):
def __init__(self, in_channels, out_channels, kernel_size, out_size, mode='nearest'):
super().__init__()
self.out_size = out_size
self.mode = mode
self.conv = nn.Conv2d(in_channels, out_channels, kernel_size, stride=1, padding=kernel_size//2)

def forward(self, x):
x = F.interpolate(x, size=self.out_size, mode=self.mode)
x = torch.relu(self.conv(x))
return x

class BasicBlockEnc(nn.Module):

def __init__(self, in_planes, stride=1):
super().__init__()

planes = in_planes*stride

self.conv1 = nn.Conv2d(in_planes, planes, kernel_size=3, stride=stride, padding=1, bias=False)
self.bn1 = nn.BatchNorm2d(planes)
self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=1, padding=1, bias=False)
self.bn2 = nn.BatchNorm2d(planes)

if stride == 1:
self.shortcut = nn.Identity()
else:
self.shortcut = nn.Sequential(
nn.Conv2d(in_planes, planes, kernel_size=1, stride=stride, bias=False),
nn.BatchNorm2d(planes)
)

def forward(self, x):
out = torch.relu(self.bn1(self.conv1(x)))
out = self.bn2(self.conv2(out))
out = out + self.shortcut(x)
out = torch.relu(out)
return out

class BasicBlockDec(nn.Module):
def __init__(self, in_planes, stride=1):
super().__init__()
planes = int(in_planes/stride)

self.conv2 = nn.Conv2d(in_planes, in_planes, kernel_size=3, stride=1, padding=1, bias=False)
self.bn2 = nn.BatchNorm2d(in_planes)
# self.bn1 could have been placed here,
# but that messes up the order of the layers when printing the class

if stride == 1:
self.conv1 = nn.Conv2d(in_planes, planes, kernel_size=3, stride=1, padding=1, bias=False)
self.bn1 = nn.BatchNorm2d(planes)
self.shortcut = nn.Sequential()
else:
self.conv1 = ResizeConv2d(in_planes, planes, kernel_size=3, scale_factor=stride)
self.bn1 = nn.BatchNorm2d(planes)
self.shortcut = nn.Sequential(
ResizeConv2d(in_planes, planes, kernel_size=3, scale_factor=stride),
nn.BatchNorm2d(planes)
)
def forward(self, x):
out = torch.relu(self.bn2(self.conv2(x)))
out = self.bn1(self.conv1(out))
out = out + self.shortcut(x)
out = torch.relu(out)
return out


class ResNet18Enc(nn.Module):

def __init__(self, num_Blocks=[2,2,2,2], z_dim=10, nc=3, linear_downsample_factor = 8):
super().__init__()
self.in_planes = 64
self.z_dim = z_dim
self.conv1 = nn.Conv2d(nc, 64, kernel_size=3, stride=2, padding=1, bias=False)
self.bn1 = nn.BatchNorm2d(64)
self.layer1 = self._make_layer(BasicBlockEnc, 64, num_Blocks[0], stride=1)
self.layer2 = self._make_layer(BasicBlockEnc, 128, num_Blocks[1], stride=2)
self.layer3 = self._make_layer(BasicBlockEnc, 256, num_Blocks[2], stride=2)
self.layer4 = self._make_layer(BasicBlockEnc, 512, num_Blocks[3], stride=2)
self.linear = nn.Linear(int(512*(128/2**len(num_Blocks))**2), 2 * z_dim, bias = False)

def _make_layer(self, BasicBlockEnc, planes, num_Blocks, stride):
strides = [stride] + [1]*(num_Blocks-1)
layers = []
for stride in strides:
layers += [BasicBlockEnc(self.in_planes, stride)]
self.in_planes = planes
return nn.Sequential(*layers)

def forward(self, x):
x = torch.relu(self.bn1(self.conv1(x)))
x = self.layer1(x)
x = self.layer2(x)
x = self.layer3(x)
x = self.layer4(x)
x = torch.flatten(x, start_dim=1, end_dim=-1).unsqueeze(1)
x = torch.relu(self.linear(x))
mu, logvar = torch.chunk(x, 2, dim=2)
return mu, logvar

class ResNet18Dec(nn.Module):

def __init__(self, spatial_dim_bottle, num_Blocks=[2,2,2,2], z_dim=10, nc=3, linear_downsample_factor =8):
super().__init__()
self.in_planes = 512
self.nc = nc
self.z_dim = z_dim


self.linear = nn.Linear(z_dim, 256)
self.firstconv = nn.Conv2d(1, 512, kernel_size=1)

self.layer4 = self._make_layer(BasicBlockDec, 256, num_Blocks[3], stride=2)
self.layer3 = self._make_layer(BasicBlockDec, 128, num_Blocks[2], stride=2)
self.layer2 = self._make_layer(BasicBlockDec, 64, num_Blocks[1], stride=2)
self.layer1 = self._make_layer(BasicBlockDec, 64, num_Blocks[0], stride=1)
self.conv1 = ResizeConv2d(64, nc, kernel_size=3, scale_factor=1)

def _make_layer(self, BasicBlockDec, planes, num_Blocks, stride):
strides = [stride] + [1]*(num_Blocks-1)
layers = []
for stride in reversed(strides):
layers += [BasicBlockDec(self.in_planes, stride)]
self.in_planes = planes
return nn.Sequential(*layers)

def forward(self, z):
x = torch.relu(self.linear(z))
x= x.view(-1, 1, 16,16)
x = self.firstconv(x)
x = self.layer4(x)
x = self.layer3(x)
x = self.layer2(x)
x = self.layer1(x)
x = torch.sigmoid(self.conv1(x))
return x


class VAEResNet18_Linear(nn.Module):
def __init__(self, nc, z_dim, input_spatial_dim):
super().__init__()
self.in_spatial_shape = input_spatial_dim
self.spat_shape_bottle = self.compute_spatial_shape(4)
self.spat_shape_bottle = (self.spat_shape_bottle[0],self.spat_shape_bottle[1])
self.encoder = ResNet18Enc(nc=nc, z_dim=z_dim)
self.decoder = ResNet18Dec(nc=nc, z_dim=z_dim, spatial_dim_bottle=self.spat_shape_bottle)
self.enc_linear = nn.Sequential(

)

def forward(self, x):
mean, logvar = self.encoder(x)
z = self.reparameterize(mean, logvar)
x = self.decoder(z)
return x, z, mean, logvar

@staticmethod
def reparameterize(mean, logvar):
std = torch.exp(logvar / 2) # in log-space, squareroot is divide by two
epsilon = torch.randn_like(std)
return epsilon * std + mean

def compute_spatial_shape(self, level: int) -> tuple[int, int]:
# TODO Add warning when shape is odd before maxpool
spatial_shape = np.array(self.in_spatial_shape)
if level == 0:
return spatial_shape
spatial_shape = np.array(self.compute_spatial_shape(level-1)) // 2
if any([s%2 != 0 for s in spatial_shape]):
raise ValueError("Can't Decode Because Input Dimension is Lost during Downsampling")
return spatial_shape
Loading
Loading