Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
eecd48d
Merge a8c66ebb98565c20f576bbf5b2fda4c8a57eec44 into 8a58cc19e838d683b…
BenjaminMidtvedt Jul 26, 2022
51c87f1
chore: autopublish 2022-07-26T13:54:44Z
github-actions[bot] Jul 26, 2022
b30c265
Remove create-badges job
BenjaminMidtvedt Jul 26, 2022
085b0e5
Delete test.py
BenjaminMidtvedt Jul 26, 2022
74b37b4
Add multi-head masked attention
JesusPinedaC Jul 26, 2022
b4debf5
Update multi-head gated attention to match parent layer
JesusPinedaC Jul 26, 2022
3ecb423
Update documentation
JesusPinedaC Jul 26, 2022
bbf7f4b
Test multi-head masked attention
JesusPinedaC Jul 27, 2022
5df728a
allow gated attention layers to use bias
JesusPinedaC Jul 27, 2022
337152e
test bias in gated attention layers
JesusPinedaC Jul 27, 2022
4eb3e10
set return_attention_weights to False to avoid multi-outputs
JesusPinedaC Jul 27, 2022
2affe63
reformat gnns/layers.py
JesusPinedaC Jul 29, 2022
26d064c
Update layers.py
JesusPinedaC Jul 29, 2022
c65f49d
Update test_layers.py
JesusPinedaC Jul 29, 2022
2ca0590
Update models.py
JesusPinedaC Jul 30, 2022
1d99b6b
Update test_models.py
JesusPinedaC Jul 30, 2022
49cf7ed
Update test_models.py
JesusPinedaC Jul 30, 2022
f455fa1
Merge pull request #129 from softmatterlab/jp/rev-MAGIK
BenjaminMidtvedt Aug 1, 2022
e73d5ed
Fix indexing problems related to tf.gather
JesusPinedaC Aug 2, 2022
71e67ff
Merge pull request #130 from softmatterlab/jp/fix-idx-gather
BenjaminMidtvedt Aug 3, 2022
790e8e2
Allow multi-inputs in ContinuousGenerator
JesusPinedaC Aug 15, 2022
d4e17c1
Fix bad conversion to integer
BenjaminMidtvedt Aug 22, 2022
ad2a95e
version bump
BenjaminMidtvedt Aug 22, 2022
fffe6b6
Merge pull request #131 from softmatterlab/jp/multi-input-generator
BenjaminMidtvedt Aug 22, 2022
af29362
Fix phase correction at focus and offset calculation
BenjaminMidtvedt Aug 26, 2022
d055d1a
Fix phase correction in propagation
BenjaminMidtvedt Aug 26, 2022
30d1489
Merge pull request #134 from softmatterlab/bm/fix-mie-phase
BenjaminMidtvedt Aug 26, 2022
277db0b
Fix mie phase out of foucs
BenjaminMidtvedt Sep 1, 2022
a6f4ba0
Fix mie phase out of foucs
BenjaminMidtvedt Sep 9, 2022
39e4c6d
Merge branch 'develop' of https://github.com/softmatterlab/DeepTrack-…
BenjaminMidtvedt Sep 9, 2022
4806835
Update README.md
giovannivolpe Sep 22, 2022
ff2aca1
Bm/version 1.4.0 (#137)
giovannivolpe Oct 4, 2022
d68fca4
Merge branch 'develop'
BenjaminMidtvedt Oct 4, 2022
5aa410b
Add tensorflow datasets to the list of dependencies.
BenjaminMidtvedt Oct 6, 2022
bfb0e03
Read requirements.txt into setup.py
BenjaminMidtvedt Oct 6, 2022
ecc509f
remove sphinx from build
BenjaminMidtvedt Oct 6, 2022
1886c67
remove create badges
BenjaminMidtvedt Oct 6, 2022
c0accf1
Create CITATION.cff
giovannivolpe Oct 24, 2022
eb04f0c
Create .zenodo.json
giovannivolpe Oct 24, 2022
0be3ef9
Update transformer models
JesusPinedaC Oct 26, 2022
d355352
Update pint_definition.py
JesusPinedaC Oct 26, 2022
6ea9326
Update requirements.txt
JesusPinedaC Oct 26, 2022
b079b69
Merge pull request #140 from softmatterlab/bm/tfd
BenjaminMidtvedt Oct 26, 2022
79da3c8
Merge pull request #145 from softmatterlab/jp/transformers
BenjaminMidtvedt Oct 26, 2022
6ef979d
create TimeDistributed CNN
JesusPinedaC Oct 28, 2022
64667cc
small fixes to lodestar
BenjaminMidtvedt Oct 30, 2022
dedcaa7
Merge pull request #146 from softmatterlab/jp/time-distributed
BenjaminMidtvedt Oct 30, 2022
af0babc
Merge pull request #147 from softmatterlab/bm/add-holo-data
BenjaminMidtvedt Oct 31, 2022
54df12a
Merge branch 'master' into develop
BenjaminMidtvedt Nov 1, 2022
04acc62
Update layers.py
JesusPinedaC Nov 8, 2022
19bd1a3
Update test_layers.py
JesusPinedaC Nov 8, 2022
9ab12a5
remove direct getter of properties
BenjaminMidtvedt Nov 9, 2022
f0d0432
Update scatterers.py
HarshithBachimanchi Nov 15, 2022
d6c4a22
Update scatterers.py
HarshithBachimanchi Nov 16, 2022
b70d9d6
mie phase fix
BenjaminMidtvedt Nov 17, 2022
0f2a041
Merge pull request #150 from softmatterlab/bm/fix-repeat-miesphere
BenjaminMidtvedt Nov 21, 2022
dad31d3
Merge branch 'develop' into hb/inline
BenjaminMidtvedt Nov 21, 2022
d34ba6a
Merge pull request #151 from HarshithBachimanchi/hb/inline
BenjaminMidtvedt Nov 21, 2022
21c9272
removed pydeepimagej from deps
BenjaminMidtvedt Nov 25, 2022
10fc4e4
Change loss input order of CGAN and PCGAN
GideonJagen Nov 28, 2022
75d13ea
Create dmdataset (dataset for graph-level regression tasks)
JesusPinedaC Nov 30, 2022
7c67ea8
Update gnns/__init__.py
JesusPinedaC Nov 30, 2022
1ca8651
Merge pull request #159 from softmatterlab/jp/more-gnns-datasets
BenjaminMidtvedt Nov 30, 2022
00028ad
Merge pull request #149 from softmatterlab/jp/gnn-gru-fix
BenjaminMidtvedt Nov 30, 2022
f93cfed
Merge pull request #157 from GideonJagen/fix-cgan-loss
BenjaminMidtvedt Nov 30, 2022
08cce3c
Add detection_linking_hela dataset
JesusPinedaC Dec 1, 2022
8e74b54
Merge pull request #160 from softmatterlab/jp/dic_hela_gnn_dataset
JesusPinedaC Dec 3, 2022
8218e77
Update dmdataset.py
JesusPinedaC Dec 5, 2022
54c409d
Create the regression_diffusion_landscape
JesusPinedaC Dec 5, 2022
7e082f0
Update scatterers.py
HarshithBachimanchi Dec 6, 2022
6c3c071
Update test_scatterers.py
HarshithBachimanchi Dec 6, 2022
e94c186
Update augmentations.py
JesusPinedaC Dec 6, 2022
50c6504
Update test_scatterers.py
HarshithBachimanchi Dec 6, 2022
48ad113
Update test_scatterers.py
HarshithBachimanchi Dec 6, 2022
cacf812
Merge pull request #162 from softmatterlab/jp/node-gnn-dataset
BenjaminMidtvedt Dec 6, 2022
8c314e8
Merge pull request #161 from HarshithBachimanchi/hb/inline
BenjaminMidtvedt Dec 6, 2022
6d885bd
Create endothelial_vs dataset
JesusPinedaC Dec 7, 2022
c7af8a8
Update layers.py
JesusPinedaC Dec 7, 2022
8563438
Update utils.py
JesusPinedaC Dec 8, 2022
093b4c3
Merge pull request #163 from softmatterlab/jp/vs
BenjaminMidtvedt Dec 8, 2022
a28097d
Merge pull request #155 from softmatterlab/bm/remove-pydeepimagej
BenjaminMidtvedt Dec 8, 2022
227db5f
Update docs link
BenjaminMidtvedt Dec 12, 2022
393e0e7
Update README.md
BenjaminMidtvedt Dec 12, 2022
a14400c
version bump
Dec 13, 2022
f32936c
version bump
Dec 13, 2022
6944ec4
Merge branch 'develop' of https://github.com/softmatterlab/DeepTrack2…
Dec 13, 2022
5d6c5a8
Update README.md
BenjaminMidtvedt Dec 13, 2022
25ba82b
Merge branch 'master' into develop
BenjaminMidtvedt Dec 13, 2022
566c9b1
Update README.md
BenjaminMidtvedt Dec 16, 2022
e225214
Update graphs.py
JesusPinedaC Dec 21, 2022
2ada318
Update test_generators.py
JesusPinedaC Dec 21, 2022
2a3a194
Update generators.py
JesusPinedaC Dec 21, 2022
10b850e
fix test
JesusPinedaC Dec 21, 2022
8fe1f47
Merge pull request #165 from softmatterlab/jp/magik-update
BenjaminMidtvedt Dec 21, 2022
5445b64
Update vae.py
JesusPinedaC Feb 18, 2023
bf13c76
Merge pull request #170 from softmatterlab/jp/fix-vae
JesusPinedaC Feb 18, 2023
2d5a11a
Bugfix in endothelial_vs dataset
Henrik-KM Mar 26, 2023
cf95064
Fix issue with repeated oneof-features (#169)
BenjaminMidtvedt Apr 11, 2023
9341f15
Update cell_migration_analysis.ipynb
JesusPinedaC Apr 11, 2023
dbb2ab2
Merge branch 'master' into develop
giovannivolpe Apr 13, 2023
7fae055
Update features.py (#189)
HarshithBachimanchi Sep 11, 2023
1413e01
added WAE (both MMD and GAN) (#185)
cmanzo Sep 12, 2023
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
5 changes: 3 additions & 2 deletions deeptrack/datasets/endothelial_vs/endothelial_vs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import tensorflow_datasets as tfds
import numpy as np
import tensorflow as tf

_DESCRIPTION = """
"""
Expand Down Expand Up @@ -34,10 +35,10 @@ def _info(self) -> tfds.core.DatasetInfo:
features=tfds.features.FeaturesDict(
{
"image": tfds.features.Image(
shape=(None, None, 1), dtype="uint16"
shape=(None, None, 1), dtype=tf.uint16
),
"label": tfds.features.Image(
shape=(None, None, 1), dtype="uint16"
shape=(None, None, 1), dtype=tf.uint16
),
}
),
Expand Down
14 changes: 7 additions & 7 deletions deeptrack/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -1307,8 +1307,8 @@ def _process_properties(self, propertydict) -> dict:

return propertydict

def get(self, image, key, **kwargs):
return self.collection[key](image)
def get(self, image, key, _ID=(), **kwargs):
return self.collection[key](image, _ID=_ID)


class OneOfDict(Feature):
Expand Down Expand Up @@ -1338,8 +1338,8 @@ def _process_properties(self, propertydict) -> dict:

return propertydict

def get(self, image, key, **kwargs):
return self.collection[key](image)
def get(self, image, key, _ID=(), **kwargs):
return self.collection[key](image, _ID=_ID)


# class Dataset(Feature):
Expand Down Expand Up @@ -1637,7 +1637,7 @@ def _process_and_get(self, images, **kwargs):
p0[0] = np.max([p0[0], 0])
p0[1] = np.max([p0[1], 0])

p0 = p0.astype(np.int)
p0 = p0.astype(int)

output_slice = output[
p0[0] : p0[0] + labelarg.shape[0],
Expand Down Expand Up @@ -2109,7 +2109,7 @@ def _check_volumes_non_overlapping(self, volume_1, volume_2, min_distance):
)

def _resample_volume_position(self, volume):
""" Draws a new position for the volume. """
"""Draws a new position for the volume."""

for pdict in volume.properties:
if "position" in pdict and "_position_sampler" in pdict:
Expand All @@ -2122,4 +2122,4 @@ def _resample_volume_position(self, volume):


# Alias
Dataset = TensorflowDataset
Dataset = TensorflowDataset
1 change: 1 addition & 0 deletions deeptrack/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from .gans import *
from .gnns import *
from .vaes import *
from .waes import *

# from .mrcnn import *
# from .yolov1 import *
Expand Down
45 changes: 33 additions & 12 deletions deeptrack/models/gans/gan.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,24 @@

layers = tf.keras.layers


@as_KerasModel
class GAN(tf.keras.Model):
"""Generative Adversarial Network (GAN) model.

Parameters:
discriminator: keras model, optional
The discriminator network.
generator: keras model, optional
The generator network.
latent_dim: int, optional
Dimension of the latent space for random vectors.
"""

def __init__(self, discriminator=None, generator=None, latent_dim=128):
super(GAN, self).__init__()

# Initialize discriminator and generator, or use default if not provided
if discriminator is None:
discriminator = self.default_discriminator()

if generator is None:
generator = self.default_generator()

Expand All @@ -21,9 +30,13 @@ def __init__(self, discriminator=None, generator=None, latent_dim=128):

def compile(self, d_optimizer, g_optimizer, loss_fn):
super(GAN, self).compile()

# Set optimizers and loss function for training
self.d_optimizer = d_optimizer
self.g_optimizer = g_optimizer
self.loss_fn = loss_fn

# Define metrics to track during training
self.d_loss_metric = tf.keras.metrics.Mean(name="d_loss")
self.g_loss_metric = tf.keras.metrics.Mean(name="g_loss")

Expand All @@ -36,17 +49,18 @@ def train_step(self, real_images):
batch_size = tf.shape(real_images)[0]
random_latent_vectors = tf.random.normal(shape=(batch_size, self.latent_dim))

# Decode them to fake images
# Generate fake images using the generator
generated_images = self.generator(random_latent_vectors)

# Combine them with real images
# Combine real and fake images
combined_images = tf.concat([generated_images, real_images], axis=0)

# Assemble labels discriminating real from fake images
# Create labels for real and fake images
labels = tf.concat(
[tf.ones((batch_size, 1)), tf.zeros((batch_size, 1))], axis=0
)
# Add random noise to the labels - important trick!

# Add random noise to labels to improve stability
labels += 0.05 * tf.random.uniform(tf.shape(labels))

# Train the discriminator
Expand All @@ -58,14 +72,13 @@ def train_step(self, real_images):
zip(grads, self.discriminator.trainable_weights)
)

# Sample random points in the latent space
# Generate new random latent vectors
random_latent_vectors = tf.random.normal(shape=(batch_size, self.latent_dim))

# Assemble labels that say "all real images"
# Create labels indicating "all real images" for generator training
misleading_labels = tf.zeros((batch_size, 1))

# Train the generator (note that we should *not* update the weights
# of the discriminator)!
# Train the generator while keeping discriminator weights fixed
with tf.GradientTape() as tape:
predictions = self.discriminator(self.generator(random_latent_vectors))
g_loss = self.loss_fn(misleading_labels, predictions)
Expand All @@ -75,12 +88,19 @@ def train_step(self, real_images):
# Update metrics
self.d_loss_metric.update_state(d_loss)
self.g_loss_metric.update_state(g_loss)

# Return updated loss metrics
return {
"d_loss": self.d_loss_metric.result(),
"g_loss": self.g_loss_metric.result(),
}

def call(self, inputs):
# Run generator
return self.generator(inputs)

def default_generator(self, latent_dim=128):
# Define the default generator architecture
return tf.keras.Sequential(
[
tf.keras.Input(shape=(latent_dim,)),
Expand All @@ -98,6 +118,7 @@ def default_generator(self, latent_dim=128):
)

def default_discriminator(self):
# Define the default discriminator architecture
return tf.keras.Sequential(
[
tf.keras.Input(shape=(64, 64, 3)),
Expand All @@ -112,4 +133,4 @@ def default_discriminator(self):
layers.Dense(1, activation="sigmoid"),
],
name="discriminator",
)
)
51 changes: 28 additions & 23 deletions deeptrack/models/vaes/vae.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
import tensorflow as tf
from tensorflow.keras import layers

from ..utils import as_KerasModel


@as_KerasModel
class VAE(tf.keras.Model):
"""Variational Autoencoder (VAE) model.

Parameters:
encoder: keras model, optional
The encoder network.
decoder: keras model, optional
The decoder network.
latent_dim: int, optional
Dimension of the latent space.
"""

def __init__(self, encoder=None, decoder=None, latent_dim=2, **kwargs):
super().__init__(**kwargs)
super(VAE, self).__init__(**kwargs)

# Dimensionality of the latent space
# Define encoder latent dimension
self.latent_dim = latent_dim

# Initialize encoder and decoder, or use defaults
if encoder is None:
self.encoder = self.default_encoder()

if decoder is None:
self.decoder = self.default_decoder()

def train_step(self, data):

data, _ = data

# Gradient tape for automatic differentiation
with tf.GradientTape() as tape:
# Encode input data and sample from latent space.
# The encoder outputs the mean and log of the variance of the
# Gaussian distribution. The log of the variance is computed
# instead of the variance for numerical stability.
Expand All @@ -32,42 +43,37 @@ def train_step(self, data):
epsilon = tf.random.normal(shape=tf.shape(z_mean))
z = z_mean + tf.exp(0.5 * z_log_var) * epsilon

# Reconstruct the input image
# Decode latent samples and compute reconstruction loss
rdata = self.decoder(z)

# Reconstruction loss
rloss = self.loss(data, rdata)

# KL divergence loss
kl_loss = -0.5 * (
1 + z_log_var - tf.square(z_mean) - tf.exp(z_log_var)
)
# Compute KL divergence loss
kl_loss = -0.5 * (1 + z_log_var - tf.square(z_mean) - tf.exp(z_log_var))
kl_loss = tf.reduce_mean(tf.reduce_sum(kl_loss, axis=1))

# Total loss
# Compute total loss
loss = rloss + kl_loss

# Compute gradients
# Compute gradients and update model weights
grads = tape.gradient(loss, self.trainable_weights)
self.optimizer.apply_gradients(zip(grads, self.trainable_weights))

# Update weights
self.optimizer.apply_gradients(
zip(grads, self.trainable_weights),
)

# Update metrics
# Update metrics for monitoring
self.compiled_metrics.update_state(data, rdata)

# Return loss values for visualization
return {
"loss": loss,
"reconstruction_loss": rloss,
"kl_loss": kl_loss,
}

def call(self, inputs):
# Use encoder to obtain latent representation
return self.encoder(inputs)

def default_encoder(self):
# Define the default encoder architecture
return tf.keras.Sequential(
[
tf.keras.Input(shape=(28, 28, 1)),
Expand All @@ -88,14 +94,13 @@ def default_encoder(self):
layers.Flatten(),
layers.Dense(16),
layers.LeakyReLU(alpha=0.2),
layers.Dense(
self.latent_dim + self.latent_dim, name="z_mean_log_var"
),
layers.Dense(self.latent_dim + self.latent_dim, name="z_mean_log_var"),
],
name="encoder",
)

def default_decoder(self):
# Define the default decoder architecture
return tf.keras.Sequential(
[
tf.keras.Input(shape=(self.latent_dim,)),
Expand Down
1 change: 1 addition & 0 deletions deeptrack/models/waes/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .wae import *
Loading