diff --git a/ImageSelector.py b/ImageSelector.py index b382e5e5..3bf43a56 100644 --- a/ImageSelector.py +++ b/ImageSelector.py @@ -24,7 +24,6 @@ import time import random import os -from model import Model from net import * from checkpointer import Checkpointer from scheduler import ComboMultiStepLR diff --git a/checkpointer.py b/checkpointer.py index b162a989..61e79b83 100644 --- a/checkpointer.py +++ b/checkpointer.py @@ -1,4 +1,4 @@ -# Copyright 2019 Stanislav Pidhorskyi +# Copyright 2019-2020 Stanislav Pidhorskyi # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/custom_adam.py b/custom_adam.py index 0fd813d1..1b648f5e 100644 --- a/custom_adam.py +++ b/custom_adam.py @@ -1,3 +1,19 @@ +# Copyright 2019-2020 Stanislav Pidhorskyi +# lr_equalization_coef was added for LREQ + +# Copyright (c) 2016- Facebook, Inc (Adam Paszke) +# Copyright (c) 2014- Facebook, Inc (Soumith Chintala) +# Copyright (c) 2011-2014 Idiap Research Institute (Ronan Collobert) +# Copyright (c) 2012-2014 Deepmind Technologies (Koray Kavukcuoglu) +# Copyright (c) 2011-2012 NEC Laboratories America (Koray Kavukcuoglu) +# Copyright (c) 2011-2013 NYU (Clement Farabet) +# Copyright (c) 2006-2010 NEC Laboratories America (Ronan Collobert, Leon Bottou, Iain Melvin, Jason Weston) +# Copyright (c) 2006 Idiap Research Institute (Samy Bengio) +# Copyright (c) 2001-2004 Idiap Research Institute (Ronan Collobert, Samy Bengio, Johnny Mariethoz) + +# https://github.com/pytorch/pytorch/blob/master/LICENSE + + import math import torch from torch.optim.optimizer import Optimizer diff --git a/dataloader.py b/dataloader.py index c7c4fc7f..6ac32c0c 100644 --- a/dataloader.py +++ b/dataloader.py @@ -1,4 +1,4 @@ -# Copyright 2019 Stanislav Pidhorskyi +# Copyright 2019-2020 Stanislav Pidhorskyi # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -13,11 +13,8 @@ # limitations under the License. # ============================================================================== -import pickle import dareblopy as db -from threading import Thread, Lock, Event import random -import threading import numpy as np import torch @@ -25,13 +22,8 @@ import torch.utils import torch.utils.data import time -import torchvision.transforms.functional as vF -from torchvision import transforms import math -from dlutils.batch_provider import batch_provider -from dlutils.shuffle import shuffle_ndarray - cpu = torch.device('cpu') diff --git a/defaults.py b/defaults.py index bfcc11a4..d0a3a595 100644 --- a/defaults.py +++ b/defaults.py @@ -1,4 +1,4 @@ -# Copyright 2019 Stanislav Pidhorskyi +# Copyright 2019-2020 Stanislav Pidhorskyi # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/fid.py b/fid.py index 8f8e666a..65c0a7b3 100644 --- a/fid.py +++ b/fid.py @@ -1,3 +1,5 @@ +# Copyright 2019-2020 Stanislav Pidhorskyi +# # Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. # # This work is licensed under the Creative Commons Attribution-NonCommercial @@ -10,31 +12,18 @@ import numpy as np import tensorflow as tf import torch -import dnnlib import dnnlib.tflib -import dnnlib.tflib as tflib import pickle from net import * -from checkpointer import Checkpointer -from scheduler import ComboMultiStepLR from model_z_gan import Model from launcher import run -from defaults import get_cfg_defaults -import lod_driver from dataloader import * import scipy.linalg from checkpointer import Checkpointer -from scheduler import ComboMultiStepLR -from dlutils import batch_provider -from dlutils.pytorch.cuda_helper import * from dlutils.pytorch import count_parameters from defaults import get_cfg_defaults -import argparse -import logging -import sys -import lreq from skimage.transform import resize from tqdm import tqdm diff --git a/fid_rec.py b/fid_rec.py index 917403ef..d9fb760a 100644 --- a/fid_rec.py +++ b/fid_rec.py @@ -1,3 +1,5 @@ +# Copyright 2019-2020 Stanislav Pidhorskyi +# # Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. # # This work is licensed under the Creative Commons Attribution-NonCommercial @@ -10,31 +12,18 @@ import numpy as np import tensorflow as tf import torch -import dnnlib import dnnlib.tflib -import dnnlib.tflib as tflib import pickle from net import * -from checkpointer import Checkpointer -from scheduler import ComboMultiStepLR from model_z_gan import Model from launcher import run -from defaults import get_cfg_defaults -import lod_driver from dataloader import * import scipy.linalg from checkpointer import Checkpointer -from scheduler import ComboMultiStepLR -from dlutils import batch_provider -from dlutils.pytorch.cuda_helper import * from dlutils.pytorch import count_parameters from defaults import get_cfg_defaults -import argparse -import logging -import sys -import lreq from skimage.transform import resize from tqdm import tqdm @@ -43,7 +32,7 @@ import utils dnnlib.tflib.init_tf() -tf_config = {'rnd.np_random_seed': 1000} +tf_config = {'rnd.np_random_seed': 1000} class FID: diff --git a/make_recon_figure_2.py b/make_recon_figure_2.py index 012ee984..55f793d8 100644 --- a/make_recon_figure_2.py +++ b/make_recon_figure_2.py @@ -24,7 +24,6 @@ import time import random import os -from model import Model from net import * from checkpointer import Checkpointer from scheduler import ComboMultiStepLR diff --git a/net.py b/net.py index ec5421e5..76b93d2f 100644 --- a/net.py +++ b/net.py @@ -1,4 +1,4 @@ -# Copyright 2019 Stanislav Pidhorskyi +# Copyright 2019-2020 Stanislav Pidhorskyi # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -20,30 +20,11 @@ from torch.nn import init from torch.nn.parameter import Parameter import numpy as np -from dlutils.pytorch import count_parameters import lreq as ln import math from registry import * -if False: - def lerp(s, e, x): - return s + (e - s) * x - - - def rsqrt(x): - return 1.0 / x ** 0.5 - - - def addcmul(x, value, tensor1, tensor2): - return x + value * tensor1 * tensor2 - - - torch.lerp = lerp - torch.rsqrt = rsqrt - torch.addcmul = addcmul - - def pixel_norm(x, epsilon=1e-8): return x * torch.rsqrt(torch.mean(x.pow(2.0), dim=1, keepdim=True) + epsilon) @@ -110,9 +91,6 @@ def __init__(self, inputs, outputs, latent_size, last=False, fused_scale=True): self.bias_2.zero_() def forward(self, x): - # if self.last: - # x = minibatch_stddev_layer(x) - x = self.conv_1(x) + self.bias_1 x = F.leaky_relu(x, 0.2) @@ -795,18 +773,6 @@ def get_statistics(self, lod): return rgb_std / rgb_std_c, layers -def minibatch_stddev_layer(x, group_size=4): - group_size = min(group_size, x.shape[0]) - size = x.shape[0] - if x.shape[0] % group_size != 0: - x = torch.cat([x, x[:(group_size - (x.shape[0] % group_size)) % group_size]]) - y = x.view(group_size, -1, x.shape[1], x.shape[2], x.shape[3]) - y = y - y.mean(dim=0, keepdim=True) - y = torch.sqrt((y ** 2).mean(dim=0) + 1e-8).mean(dim=[1, 2, 3], keepdim=True) - y = y.repeat(group_size, 1, x.shape[2], x.shape[3]) - return torch.cat([x, y], dim=1)[:size] - - image_size = 64 # Number of channels in the training images. For color images this is 3 @@ -1003,8 +969,6 @@ def encode(self, x, lod): x = F.interpolate(x, 28) x = x.view(x.shape[0], 28 * 28) - # styles = torch.zeros(x.shape[0], 1, self.latent_size) - x = self.fc_1(x) x = F.leaky_relu(x, 0.2) x = self.fc_2(x) @@ -1039,8 +1003,6 @@ def decode(self, x, lod, blend_factor, noise): x = x[:, 0] # no styles x.view(x.shape[0], self.latent_size) - # styles = torch.zeros(x.shape[0], 1, self.latent_size) - x = self.fc_1(x) x = F.leaky_relu(x, 0.2) x = self.fc_2(x) diff --git a/ppl.py b/ppl.py index 47f48aea..9b73ed97 100644 --- a/ppl.py +++ b/ppl.py @@ -1,3 +1,5 @@ +# Copyright 2019 Stanislav Pidhorskyi +# # Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. # # This work is licensed under the Creative Commons Attribution-NonCommercial @@ -10,31 +12,15 @@ import numpy as np import tensorflow as tf import torch -import dnnlib import dnnlib.tflib -import dnnlib.tflib as tflib import pickle from net import * from checkpointer import Checkpointer -from scheduler import ComboMultiStepLR -#from model_z_gan import Model from model_z_gan import Model from launcher import run -from defaults import get_cfg_defaults -import lod_driver - - -from checkpointer import Checkpointer -from scheduler import ComboMultiStepLR - -from dlutils import batch_provider from dlutils.pytorch.cuda_helper import * from dlutils.pytorch import count_parameters from defaults import get_cfg_defaults -import argparse -import logging -import sys -import lreq from skimage.transform import resize import tqdm @@ -42,7 +28,7 @@ from matplotlib import pyplot as plt dnnlib.tflib.init_tf() -tf_config = {'rnd.np_random_seed': 1000} +tf_config = {'rnd.np_random_seed': 1000} # Normalize batch of vectors.