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

exchange master branch #78

Open
wants to merge 12 commits into
base: model_builder
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__pycache__
.ipynb_checkpoints
*.egg-info
4 changes: 1 addition & 3 deletions nnvision/datasets/monkey_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
from collections import namedtuple, Iterable
import os
from pathlib import Path
from mlutils.data.samplers import RepeatsBatchSampler
from .utility import get_validation_split, ImageCache, get_cached_loader, get_fraction_of_training_images
from nnfabrik.utility.nn_helpers import get_module_output, set_random_seed, get_dims_for_loader_dict
from nnfabrik.utility.nn_helpers import set_random_seed, get_dims_for_loader_dict
from nnfabrik.utility.dj_helpers import make_hash


Expand Down Expand Up @@ -177,7 +176,6 @@ def monkey_static_loader(dataset,
dataloaders["validation"][data_key] = val_loader
dataloaders["test"][data_key] = test_loader


if store_data_info and not os.path.exists(stats_path):

in_name, out_name = next(iter(list(dataloaders["train"].values())[0]))._fields
Expand Down
6 changes: 3 additions & 3 deletions nnvision/datasets/mouse_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import warnings

import numpy as np
from mlutils.data.datasets import StaticImageSet, FileTreeDataset
from mlutils.data.transforms import Subsample, ToTensor, NeuroNormalizer, AddBehaviorAsChannels, SelectInputChannel
from mlutils.data.samplers import SubsetSequentialSampler
from neuralpredictors.data.datasets import StaticImageSet, FileTreeDataset
from neuralpredictors.data.transforms import Subsample, ToTensor, NeuroNormalizer, AddBehaviorAsChannels, SelectInputChannel
from neuralpredictors.data.samplers import SubsetSequentialSampler
from nnfabrik.utility.nn_helpers import set_random_seed
from .utility import get_oracle_dataloader
from torch.utils.data import DataLoader
Expand Down
2 changes: 1 addition & 1 deletion nnvision/datasets/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from skimage.transform import rescale
from collections import namedtuple, Iterable
import os
from mlutils.data.samplers import RepeatsBatchSampler
from neuralpredictors.data.samplers import RepeatsBatchSampler


def get_oracle_dataloader(dat,
Expand Down
2 changes: 1 addition & 1 deletion nnvision/legacy/featurevis/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from nnfabrik.main import Dataset, schema
from nnfabrik.utility.dj_helpers import make_hash
from . import integration
from mlutils.data.datasets import StaticImageSet
from neuralpredictors.data.datasets import StaticImageSet


class TrainedEnsembleModelTemplate(dj.Manual):
Expand Down
6 changes: 3 additions & 3 deletions nnvision/legacy/nnfabrik/datasets/mouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from torch.utils.data import DataLoader
from torch.utils.data.sampler import SubsetRandomSampler

from mlutils.data.datasets import StaticImageSet
from mlutils.data.transforms import Subsample, ToTensor, NeuroNormalizer, AddBehaviorAsChannels
from mlutils.data.samplers import SubsetSequentialSampler
from neuralpredictors.data.datasets import StaticImageSet
from neuralpredictors.data.transforms import Subsample, ToTensor, NeuroNormalizer, AddBehaviorAsChannels
from neuralpredictors.data.samplers import SubsetSequentialSampler

from ..utility.nn_helpers import set_random_seed

Expand Down
4 changes: 2 additions & 2 deletions nnvision/legacy/nnfabrik/datasets/movies.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Mouse Movie Datasets
import torch
from mlutils.data.datasets import MovieSet
from mlutils.data.transforms import Subsequence, Subsample, Normalizer, ToTensor
from neuralpredictors.data.datasets import MovieSet
from neuralpredictors.data.transforms import Subsequence, Subsample, Normalizer, ToTensor
from torch.utils.data.sampler import SubsetRandomSampler
from torch.utils.data import DataLoader
import numpy as np
Expand Down
2 changes: 1 addition & 1 deletion nnvision/legacy/nnfabrik/datasets/sysident_v1_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#from retina.retina import warp_image
from collections import namedtuple, Iterable
import os
from mlutils.data.samplers import RepeatsBatchSampler
from neuralpredictors.data.samplers import RepeatsBatchSampler


class ImageCache:
Expand Down
4 changes: 2 additions & 2 deletions nnvision/legacy/nnfabrik/measures/measures.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import warnings
import numpy as np
import torch
from mlutils.measures import corr
from mlutils.training import eval_state, device_state
from neuralpredictors.measures import corr
from neuralpredictors.training import eval_state, device_state
import types
import contextlib
import warnings
Expand Down
2 changes: 1 addition & 1 deletion nnvision/legacy/nnfabrik/models/dynamic_models/cores.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from torch.nn import functional as F, Parameter

from .misc import DepthSeparableConv2d
from mlutils.regularizers import LaplaceL2, LaplaceL23d
from neuralpredictors.regularizers import LaplaceL2, LaplaceL23d
from . import logger as log


Expand Down
2 changes: 1 addition & 1 deletion nnvision/legacy/nnfabrik/models/dynamic_models/readouts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pprint import pformat

from mlutils.layers.readouts import SpatialTransformerPooled3d
from neuralpredictors.layers.readouts import SpatialTransformerPooled3d
from torch.nn import ModuleDict

from . import logger as log
Expand Down
50 changes: 25 additions & 25 deletions nnvision/legacy/nnfabrik/models/gaussian_readout_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
from torch.nn import Parameter
from torch.nn import functional as F
from torch.nn import ModuleDict
from mlutils.constraints import positive
from mlutils.layers.cores import DepthSeparableConv2d, Core2d, Stacked2dCore
from neuralpredictors.constraints import positive
from neuralpredictors.layers.cores import DepthSeparableConv2d, Core2d, Stacked2dCore
from ..utility.nn_helpers import get_io_dims, get_module_output, set_random_seed, get_dims_for_loader_dict
from mlutils import regularizers
from mlutils.layers.readouts import PointPooled2d
from mlutils.layers.legacy import Gaussian2d
from neuralpredictors import regularizers
from neuralpredictors.layers.readouts import PointPooled2d
from neuralpredictors.layers.legacy import Gaussian2d
from .pretrained_models import TransferLearningCore

# Squeeze and Excitation Block
Expand Down Expand Up @@ -69,7 +69,7 @@ def __init__(
input_kern: kernel size of the first layer (i.e. the input layer)
hidden_kern: kernel size of each hidden layer's kernel
layers: number of layers
gamma_input: regularizer factor for the input weights (default: LaplaceL2, see mlutils.regularizers)
gamma_input: regularizer factor for the input weights (default: LaplaceL2, see neuralpredictors.regularizers)
skip: Adds a skip connection
final_nonlinearity: Boolean, if true, appends an ELU layer after the last BatchNorm (if BN=True)
bias: Adds a bias layer. Note: bias and batch_norm can not both be true
Expand All @@ -81,7 +81,7 @@ def __init__(
the kernel size (recommended). Setting Padding to 0 is not recommended and leads to artefacts,
zero is the default however to recreate backwards compatibility.
normalize_laplace_regularizer: Boolean, if set to True, will use the LaplaceL2norm function from
mlutils.regularizers, which returns the regularizer as |laplace(filters)| / |filters|
neuralpredictors.regularizers, which returns the regularizer as |laplace(filters)| / |filters|
input_regularizer: String that must match one of the regularizers in ..regularizers
stack: Int or iterable. Selects which layers of the core should be stacked for the readout.
default value will stack all layers on top of each other.
Expand Down Expand Up @@ -204,7 +204,7 @@ def __init__(
input_kern: kernel size of the first layer (i.e. the input layer)
hidden_kern: kernel size of each hidden layer's kernel
layers: number of layers
gamma_input: regularizer factor for the input weights (default: LaplaceL2, see mlutils.regularizers)
gamma_input: regularizer factor for the input weights (default: LaplaceL2, see neuralpredictors.regularizers)
skip: Adds a skip connection
final_nonlinearity: Boolean, if true, appends an ELU layer after the last BatchNorm (if BN=True)
bias: Adds a bias layer. Note: bias and batch_norm can not both be true
Expand All @@ -216,7 +216,7 @@ def __init__(
the kernel size (recommended). Setting Padding to 0 is not recommended and leads to artefacts,
zero is the default however to recreate backwards compatibility.
normalize_laplace_regularizer: Boolean, if set to True, will use the LaplaceL2norm function from
mlutils.regularizers, which returns the regularizer as |laplace(filters)| / |filters|
neuralpredictors.regularizers, which returns the regularizer as |laplace(filters)| / |filters|
input_regularizer: String that must match one of the regularizers in ..regularizers
stack: Int or iterable. Selects which layers of the core should be stacked for the readout.
default value will stack all layers on top of each other.
Expand Down Expand Up @@ -359,16 +359,16 @@ def se_core_gauss_readout(dataloaders, seed, hidden_channels=32, input_kern=13,
depth_separable=False,
):
"""
Model class of a stacked2dCore (from mlutils) and a pointpooled (spatial transformer) readout
Model class of a stacked2dCore (from neuralpredictors) and a pointpooled (spatial transformer) readout

Args:
dataloaders: a dictionary of dataloaders, one loader per session
in the format {'data_key': dataloader object, .. }
seed: random seed
elu_offset: Offset for the output non-linearity [F.elu(x + self.offset)]

all other args: See Documentation of Stacked2dCore in mlutils.layers.cores and
PointPooled2D in mlutils.layers.readouts
all other args: See Documentation of Stacked2dCore in neuralpredictors.layers.cores and
PointPooled2D in neuralpredictors.layers.readouts

Returns: An initialized model which consists of model.core and model.readout
"""
Expand Down Expand Up @@ -404,7 +404,7 @@ def regularizer(self, data_key):

set_random_seed(seed)

# get a stacked2D core from mlutils
# get a stacked2D core from neuralpredictors
core = SE2dCore(input_channels=input_channels[0],
hidden_channels=hidden_channels,
input_kern=input_kern,
Expand Down Expand Up @@ -451,16 +451,16 @@ def ds_core_gauss_readout(dataloaders, seed, hidden_channels=32, input_kern=13,
gamma_readout=4, elu_offset=0, stack=None,
):
"""
Model class of a stacked2dCore (from mlutils) and a pointpooled (spatial transformer) readout
Model class of a stacked2dCore (from neuralpredictors) and a pointpooled (spatial transformer) readout

Args:
dataloaders: a dictionary of dataloaders, one loader per session
in the format {'data_key': dataloader object, .. }
seed: random seed
elu_offset: Offset for the output non-linearity [F.elu(x + self.offset)]

all other args: See Documentation of Stacked2dCore in mlutils.layers.cores and
PointPooled2D in mlutils.layers.readouts
all other args: See Documentation of Stacked2dCore in neuralpredictors.layers.cores and
PointPooled2D in neuralpredictors.layers.readouts

Returns: An initialized model which consists of model.core and model.readout
"""
Expand Down Expand Up @@ -496,7 +496,7 @@ def regularizer(self, data_key):

set_random_seed(seed)

# get a stacked2D core from mlutils
# get a stacked2D core from neuralpredictors
core = DepthSeparableCore(input_channels=input_channels[0],
hidden_channels=hidden_channels,
input_kern=input_kern,
Expand Down Expand Up @@ -540,16 +540,16 @@ def ds_core_point_readout(dataloaders, seed, hidden_channels=32, input_kern=13,
init_range=0.2, gamma_readout=0.1, elu_offset=0, stack=None,
):
"""
Model class of a stacked2dCore (from mlutils) and a pointpooled (spatial transformer) readout
Model class of a stacked2dCore (from neuralpredictors) and a pointpooled (spatial transformer) readout

Args:
dataloaders: a dictionary of dataloaders, one loader per session
in the format {'data_key': dataloader object, .. }
seed: random seed
elu_offset: Offset for the output non-linearity [F.elu(x + self.offset)]

all other args: See Documentation of Stacked2dCore in mlutils.layers.cores and
PointPooled2D in mlutils.layers.readouts
all other args: See Documentation of Stacked2dCore in neuralpredictors.layers.cores and
PointPooled2D in neuralpredictors.layers.readouts

Returns: An initialized model which consists of model.core and model.readout
"""
Expand Down Expand Up @@ -583,7 +583,7 @@ def regularizer(self, data_key):

set_random_seed(seed)

# get a stacked2D core from mlutils
# get a stacked2D core from neuralpredictors
core = DepthSeparableCore(input_channels=input_channels[0],
hidden_channels=hidden_channels,
input_kern=input_kern,
Expand Down Expand Up @@ -627,16 +627,16 @@ def stacked2d_core_gaussian_readout(dataloaders, seed, hidden_channels=32, input
gamma_readout=0.1, elu_offset=0, stack=None,
):
"""
Model class of a stacked2dCore (from mlutils) and a pointpooled (spatial transformer) readout
Model class of a stacked2dCore (from neuralpredictors) and a pointpooled (spatial transformer) readout

Args:
dataloaders: a dictionary of dataloaders, one loader per session
in the format {'data_key': dataloader object, .. }
seed: random seed
elu_offset: Offset for the output non-linearity [F.elu(x + self.offset)]

all other args: See Documentation of Stacked2dCore in mlutils.layers.cores and
PointPooled2D in mlutils.layers.readouts
all other args: See Documentation of Stacked2dCore in neuralpredictors.layers.cores and
PointPooled2D in neuralpredictors.layers.readouts

Returns: An initialized model which consists of model.core and model.readout
"""
Expand Down Expand Up @@ -670,7 +670,7 @@ def regularizer(self, data_key):

set_random_seed(seed)

# get a stacked2D core from mlutils
# get a stacked2D core from neuralpredictors
core = Stacked2dCore(input_channels=input_channels[0],
hidden_channels=hidden_channels,
input_kern=input_kern,
Expand Down
4 changes: 2 additions & 2 deletions nnvision/legacy/nnfabrik/models/pretrained_models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from mlutils.layers.readouts import PointPooled2d
from mlutils.layers.cores import Core2d, Core
from neuralpredictors.layers.readouts import PointPooled2d
from neuralpredictors.layers.cores import Core2d, Core
from ..utility.nn_helpers import get_io_dims, get_module_output, set_random_seed, get_dims_for_loader_dict

from itertools import count
Expand Down
14 changes: 7 additions & 7 deletions nnvision/legacy/nnfabrik/models/v1_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from torch import nn as nn
from torch.nn import functional as F

from mlutils.layers.readouts import PointPooled2d
from mlutils.layers.cores import Stacked2dCore
from mlutils.training import eval_state
from neuralpredictors.layers.readouts import PointPooled2d
from neuralpredictors.layers.cores import Stacked2dCore
from neuralpredictors.training import eval_state

from .pretrained_models import TransferLearningCore
from ..utility.nn_helpers import get_io_dims, get_module_output, set_random_seed, get_dims_for_loader_dict
Expand Down Expand Up @@ -47,16 +47,16 @@ def stacked2d_core_point_readout(dataloaders, seed, hidden_channels=32, input_ke
gamma_readout=0.1, elu_offset=0, stack=None, readout_reg_avg=False,
use_avg_reg=False):
"""
Model class of a stacked2dCore (from mlutils) and a pointpooled (spatial transformer) readout
Model class of a stacked2dCore (from neuralpredictors) and a pointpooled (spatial transformer) readout

Args:
dataloaders: a dictionary of dataloaders, one loader per session
in the format {'data_key': dataloader object, .. }
seed: random seed
elu_offset: Offset for the output non-linearity [F.elu(x + self.offset)]

all other args: See Documentation of Stacked2dCore in mlutils.layers.cores and
PointPooled2D in mlutils.layers.readouts
all other args: See Documentation of Stacked2dCore in neuralpredictors.layers.cores and
PointPooled2D in neuralpredictors.layers.readouts

Returns: An initialized model which consists of model.core and model.readout
"""
Expand Down Expand Up @@ -109,7 +109,7 @@ def tracked_values(self):

set_random_seed(seed)

# get a stacked2D core from mlutils
# get a stacked2D core from neuralpredictors
core = Stacked2dCore(input_channels=input_channels[0],
hidden_channels=hidden_channels,
input_kern=input_kern,
Expand Down
2 changes: 1 addition & 1 deletion nnvision/legacy/nnfabrik/training/dynamic_trainers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections import namedtuple

from mlutils.measures import PoissonLoss3d
from neuralpredictors.measures import PoissonLoss3d


def slice_iter(n, step):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from mlutils.measures import PoissonLoss3d
from neuralpredictors.measures import PoissonLoss3d
from .utils import (
corr,
ptcorr,
Expand All @@ -8,7 +8,7 @@
correlation_closure,
compute_scores,
)
from mlutils.training import cycle_datasets, early_stopping
from neuralpredictors.training import cycle_datasets, early_stopping
from tqdm import tqdm
from logging import getLogger
from itertools import product, repeat
Expand Down
8 changes: 4 additions & 4 deletions nnvision/legacy/nnfabrik/training/trainers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
from scipy import stats
from tqdm import tqdm

from mlutils import measures
from mlutils.measures import *
from mlutils.training import early_stopping, MultipleObjectiveTracker, eval_state, cycle_datasets, Exhauster, LongCycler
from neuralpredictors import measures
from neuralpredictors.measures import *
from neuralpredictors.training import early_stopping, MultipleObjectiveTracker, eval_state, cycle_datasets, Exhauster, LongCycler
from ..utility.nn_helpers import set_random_seed

from ..utility import metrics
Expand All @@ -32,7 +32,7 @@ def early_stop_trainer(model, seed, stop_function='corr_stop',
'exp_stop'
'poisson_stop'
loss_function: has to be a string that gets evaluated with eval()
Loss functions that are built in at mlutils that can
Loss functions that are built in at neuralpredictors that can
be selected in the trainer config are:
'PoissonLoss'
'GammaLoss'
Expand Down
4 changes: 2 additions & 2 deletions nnvision/legacy/nnfabrik/utility/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import torch
from scipy import stats

from mlutils.measures import PoissonLoss, corr
from mlutils.training import eval_state
from neuralpredictors.measures import PoissonLoss, corr
from neuralpredictors.training import eval_state


def model_predictions(loader, model, data_key, device):
Expand Down
2 changes: 1 addition & 1 deletion nnvision/legacy/nnfabrik/utility/nn_helpers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# helper functions concerning the ANN architecture

import torch
from mlutils.training import eval_state
from neuralpredictors.training import eval_state
import numpy as np
import random

Expand Down
Loading