Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • daconcea/fidle
  • bossardl/fidle
  • Julie.Remenant/fidle
  • abijolao/fidle
  • monsimau/fidle
  • karkars/fidle
  • guilgautier/fidle
  • cailletr/fidle
  • talks/fidle
9 results
Show changes
Showing
with 6726 additions and 242 deletions
# ------------------------------------------------------------------
# _____ _ _ _
# | ___(_) __| | | ___
# | |_ | |/ _` | |/ _ \
# | _| | | (_| | | __/
# |_| |_|\__,_|_|\___| GAN / Generators
# ------------------------------------------------------------------
# Formation Introduction au Deep Learning (FIDLE)
# CNRS/MIAI - https://fidle.cnrs.fr
# ------------------------------------------------------------------
# JL Parouty (Mars 2024)
import numpy as np
import torch.nn as nn
# -----------------------------------------------------------------------------
# -- Generator n°1
# -----------------------------------------------------------------------------
#
class Generator_1(nn.Module):
def __init__(self, latent_dim=None, data_shape=None):
super().__init__()
self.latent_dim = latent_dim
self.img_shape = data_shape
print('init generator 1 : ',latent_dim,' to ',data_shape)
self.model = nn.Sequential(
nn.Linear(latent_dim, 128),
nn.ReLU(),
nn.Linear(128,256),
nn.BatchNorm1d(256, 0.8),
nn.ReLU(),
nn.Linear(256, 512),
nn.BatchNorm1d(512, 0.8),
nn.ReLU(),
nn.Linear(512, 1024),
nn.BatchNorm1d(1024, 0.8),
nn.ReLU(),
nn.Linear(1024, int(np.prod(data_shape))),
nn.Sigmoid()
)
def forward(self, z):
img = self.model(z)
img = img.view(img.size(0), *self.img_shape)
return img
# -----------------------------------------------------------------------------
# -- Generator n°1
# -----------------------------------------------------------------------------
#
class Generator_2(nn.Module):
def __init__(self, latent_dim=None, data_shape=None):
super().__init__()
self.latent_dim = latent_dim
self.img_shape = data_shape
print('init generator 2 : ',latent_dim,' to ',data_shape)
self.model = nn.Sequential(
nn.Linear(latent_dim, 7*7*64),
nn.Unflatten(1, (64,7,7)),
# nn.UpsamplingNearest2d( scale_factor=2 ),
nn.UpsamplingBilinear2d( scale_factor=2 ),
nn.Conv2d( 64,128, (3,3), stride=(1,1), padding=(1,1) ),
nn.ReLU(),
nn.BatchNorm2d(128),
# nn.UpsamplingNearest2d( scale_factor=2 ),
nn.UpsamplingBilinear2d( scale_factor=2 ),
nn.Conv2d( 128,256, (3,3), stride=(1,1), padding=(1,1)),
nn.ReLU(),
nn.BatchNorm2d(256),
nn.Conv2d( 256,1, (5,5), stride=(1,1), padding=(2,2)),
nn.Sigmoid()
)
def forward(self, z):
img_nchw = self.model(z)
img_nhwc = img_nchw.permute(0, 2, 3, 1) # reformat from NCHW to NHWC
# img = img.view(img.size(0), *self.img_shape) # reformat from NCHW to NHWC
return img_nhwc
# ------------------------------------------------------------------
# _____ _ _ _
# | ___(_) __| | | ___
# | |_ | |/ _` | |/ _ \
# | _| | | (_| | | __/
# |_| |_|\__,_|_|\___| GAN / QuickDrawDataModule
# ------------------------------------------------------------------
# Formation Introduction au Deep Learning (FIDLE)
# CNRS/MIAI - https://fidle.cnrs.fr
# ------------------------------------------------------------------
# JL Parouty (Mars 2024)
import numpy as np
import torch
from lightning import LightningDataModule
from torch.utils.data import DataLoader
class QuickDrawDataModule(LightningDataModule):
def __init__( self, dataset_file='./sheep.npy', scale=1., batch_size=64, num_workers=4 ):
super().__init__()
print('\n---- QuickDrawDataModule initialization ----------------------------')
print(f'with : scale={scale} batch size={batch_size}')
self.scale = scale
self.dataset_file = dataset_file
self.batch_size = batch_size
self.num_workers = num_workers
self.dims = (28, 28, 1)
self.num_classes = 10
def prepare_data(self):
pass
def setup(self, stage=None):
print('\nDataModule Setup :')
# Load dataset
# Called at the beginning of each stage (train,val,test)
# Here, whatever the stage value, we'll have only one set.
data = np.load(self.dataset_file)
print('Original dataset shape : ',data.shape)
# Rescale
n=int(self.scale*len(data))
data = data[:n]
print('Rescaled dataset shape : ',data.shape)
# Normalize, reshape and shuffle
data = data/255
data = data.reshape(-1,28,28,1)
data = torch.from_numpy(data).float()
print('Final dataset shape : ',data.shape)
print('Dataset loaded and ready.')
self.data_train = data
def train_dataloader(self):
# Note : Numpy ndarray is Dataset compliant
# Have map-style interface. See https://pytorch.org/docs/stable/data.html
return DataLoader( self.data_train, batch_size=self.batch_size, num_workers=self.num_workers )
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
python==3.10
jupyterlab
pytorch
torchvision
tqdm
matplotlib
einops
datasets
\ No newline at end of file
image diff could not be displayed: it is too large. Options to address this: view the blob.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
#!/bin/bash
#OAR -n VAE with CelebA
#OAR -n Full convolutions
#OAR -t gpu
#OAR -l /nodes=1/gpudevice=1,walltime=01:00:00
#OAR --stdout _batch/VAE_CelebA_%jobid%.out
#OAR --stderr _batch/VAE_CelebA_%jobid%.err
#OAR --stdout full_convolutions_%jobid%.out
#OAR --stderr full_convolutions_%jobid%.err
#OAR --project fidle
#---- For cpu
# use :
# OAR -l /nodes=1/core=32,walltime=01:00:00
#---- Note for cpu, set :
# OAR -l /nodes=1/core=32,walltime=02:00:00
# and add a 2>/dev/null to ipython xxx
# -----------------------------------------------
......@@ -17,20 +16,45 @@
# | '_ \ / _` | __/ __| '_ \
# | |_) | (_| | || (__| | | |
# |_.__/ \__,_|\__\___|_| |_|
# VAE CelebA at GRICAD
# Fidle at GRICAD
# -----------------------------------------------
#
# <!-- TITLE --> [K3GTSRB10] - OAR batch script submission
# <!-- DESC --> Bash script for an OAR batch submission of an ipython code
# <!-- AUTHOR : Jean-Luc Parouty (CNRS/SIMaP) -->
CONDA_ENV=deeplearning2
RUN_DIR=~/fidle/VAE
RUN_IPYNB=05.1-Batch-01.ipynb
# ==== Notebook parameters =========================================
CONDA_ENV='fidle'
NOTEBOOK_DIR="~/fidle/GTSRB"
SCRIPT_IPY="03-Better-convolutions.py"
# ---- Environment vars used to override notebook/script parameters
# 'enhanced_dir', 'model_name', 'dataset_name', 'batch_size', 'epochs', 'scale', 'fit_verbosity'
export FIDLE_OVERRIDE_GTSRB3_run_dir="./data"
export FIDLE_OVERRIDE_GTSRB3_enhanced_dir="./run/GTSRB3"
export FIDLE_OVERRIDE_GTSRB3_model_name="model_01"
export FIDLE_OVERRIDE_GTSRB3_dataset_name="set-24x24-L"
export FIDLE_OVERRIDE_GTSRB3_batch_size=64
export FIDLE_OVERRIDE_GTSRB3_epochs=5
export FIDLE_OVERRIDE_GTSRB3_scale=1
export FIDLE_OVERRIDE_GTSRB3_fit_verbosity=0
# ==================================================================
# ---- Cuda Conda initialization
#
echo '------------------------------------------------------------'
echo "Start : $0"
echo '------------------------------------------------------------'
#
echo "Notebook dir : $NOTEBOOK_DIR"
echo "Script : $SCRIPT_IPY"
echo "Environment : $CONDA_ENV"
echo '------------------------------------------------------------'
env | grep FIDLE_OVERRIDE | awk 'BEGIN { FS = "=" } ; { printf("%-35s : %s\n",$1,$2) }'
echo '------------------------------------------------------------'
source /applis/environments/cuda_env.sh dahu 10.0
source /applis/environments/conda.sh
#
......@@ -38,6 +62,8 @@ conda activate "$CONDA_ENV"
# ---- Run it...
#
cd $RUN_DIR
cd $NOTEBOOK_DIR
ipython "$SCRIPT_IPY"
jupyter nbconvert --to notebook --execute "$RUN_IPYNB"
echo 'Done.'
This diff is collapsed.