Giter Club home page Giter Club logo

mimicry's People

Contributors

kwotsin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mimicry's Issues

How to judge the training process is correct

Thanks for your code! I am trying to add a new module to the SNGAN model, but I don't know how to judge my model is correct during the training since it's not like the classification task which can use the loss function to judge if the classifier is trained well. Can you give me some advice on it? thanks!

bugs in README.md and Documentation about evaluate

The Argument which is in torch_mimicry.metrics.evaluate() should be dataset ,but not dataset_name

err:
fid_score() got an unexpected keyword argument 'dataset_name'

README.md:

import torch
import torch.optim as optim
import torch_mimicry as mmc
from torch_mimicry.nets import sngan

# Data handling objects
... ...

# Start training
... ...

# Evaluate fid
mmc.metrics.evaluate(
    metric='fid',
    log_dir='./log/example',
    netG=netG,
    dataset_name='cifar10',     # should be dataset='cifar10'
    num_real_samples=50000,
    num_fake_samples=50000,
    evaluate_step=100000,
    device=device)

Documentation:
# Evaluate fid

I think that's why:
argument: dataset

def fid_score(num_real_samples,
              num_fake_samples,
              netG,
              dataset, #  The argument which is in torch_mimicry.metrics.evaluate() should be same as this one
              seed=0,
              device=None,
              batch_size=50,
              verbose=True,
              stats_file=None,
              log_dir='./log'):

size mismatch for block4.c2.weight

Dear Kwotsin:

Hi, When I use the dataset

LSUN-Bedroom | Train | 128 x 128

The data is 128x128 size, right?

So I changed the example file in https://github.com/kwotsin/mimicry/blob/master/examples/sngan_example.py

the original one it below:

# Define models and optimizers
netG = sngan.SNGANGenerator32().to(device)
netD = sngan.SNGANDiscriminator32().to(device)

I guess I have to change it into 128, that is:

netG = sngan.SNGANGenerator128().to(device)
netD = sngan.SNGANDiscriminator128().to(device)

But when I changed it to 128 , the error happened(size mismatch)
If I keep 32, the original one. the code can be running without any issues...
Did I missed anything? Looking forward to getting your feedback. Thank you in advance!!!

Best regards,
Edward

Evaluation settings question

I was wondering if you could clarify some evaluation details for the models/datasets listed in the readme tables. In particular:

  1. Which training splits were used (e.g., "train" for training and "test" for testing, "all" for both, etc...)?

  2. Were the scores obtained from a single training run of a model? Or, were multiple models trained with the same hyper-parameters, and the best model used?

Apologies if these details are already written somewhere!

Did update code base without tensorflow ??

Hi, I see your code, including many tensorflow used ,such as
compute_fidcompute_kid, compute_inception_score, and so on

Would you plan to update pytorch code for those function??

Difference of spectral norm conv2d in Dblock/DBlockOptimized

Hi~ thanks for your great contribution!

I have a question for the implementation of Dblock and DBlockOptimized. When I was trying to visualize the spectral norm of some layers, I noticed that you have two version of implementation of SN: class SNConv2d in torch_mimicry/modules/spectral_norm.py and function SNConv2d in torch_mimicry/modules/layers.py. If it is true, in Dblock and DBlockOptimized, class SNConv2d with spectral_norm=True by default. However, I feel little confused when i run the following code:

  • Simply the following lines:

    from torch_mimicry.modules.resblocks import DBlockOptimized, DBlock, GBlock
    if __name__ == "__main__":
        block  = DBlockOptimized(3,128)
        print(block)

    the output was:

    DBlockOptimized(
      (c1): Conv2d(3, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
      (c2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
      (c_sc): Conv2d(3, 128, kernel_size=(1, 1), stride=(1, 1))
      (activation): ReLU(inplace=True)
    )

    I checked Conv2d in that block and it seems that it implemented SN using pytorch official spectral norm since the Conv2d has attribute weight_orig, which origins from pytorch official implementation.

  • Copied the whole file of torch_mimicry/modules/resblocks.py and add the following lines:

    ######
    ...
    contents of resblock.py
    ...
    ######
    
    ## adding the following lines
    if __name__ == "__main__":
        block  = DBlockOptimized(3,128)
        print(block)

    the output was:

    DBlockOptimized(
      (c1): SNConv2d(3, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
      (c2): SNConv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1))
      (c_sc): SNConv2d(3, 128, kernel_size=(1, 1), stride=(1, 1))
      (activation): ReLU(inplace=True)
    )

    here the SN is implemented as in class SNConv2d by the author.

Since class SNConv2d has a more convenient way to inspect the spectral norm(it has related function to do this directly), I wonder what caused this difference. Also when I call SNGANDiscriminator32 and print its modules, results show that all the SN conv2d is implemented by pytorch official SN function/wrapper. If you've already figured it out, plz tell me how to switch to class SNConv2d .

THANKS!

Generate visual results

Hi, will it be possible to generate some images to make some visual checks of the network performances?

Some cons when using metric...

Hi, thank you for your contributions! I found this repo really easy to follow.

However, when I called mmc.metrics.evaluate to evaluate FID score, it turns out that the path to dataset is bound to './datasets', which might not be convenient if someone put their datasets out of the GAN project.

Also, would you mind providing some details of parameter combinations(i.e. batch_size, n_dis in training process and num_samples, num_real_samples and num_fake_samples in evaluating) by which the model can achieve the baseline's performance(IS, FID, KID)?

dtype bugs on windows10

windows10
python3.7
torch 1.7
torchvision 0.8

Error:

RuntimeError: Expected tensor for argument #1 'indices' to have scalar type Long; but got torch.cuda.IntTensor instead (while checking arguments for embedding)

Solution

code line

def _get_fixed_labels(self, num_images, num_classes):
        """
        Produces fixed class labels for generating fixed images.
        """
        labels = np.array([i % num_classes for i in range(num_images)])
        labels = torch.from_numpy(labels).to(self.device)

        return labels

to

def _get_fixed_labels(self, num_images, num_classes):
        """
        Produces fixed class labels for generating fixed images.
        """
        labels = np.array([i % num_classes for i in range(num_images)]).astype('int64')
        labels = torch.from_numpy(labels).to(self.device)

        return labels

I don't know exactly why but it works well

Evaluation on the test set

Hi, thanks for the excellent work.
But I noticed that the test set is not available for evaluation, because you don't specify the split argument in the metrics functions. I think it will load the train set for evaluating FID by default. Many GAN papers including SSGAN splits the data set as a train set and a test set. I guess that they evaluated their models using the test set.

Another minor concern is that the inception model will be downloaded and stored in each experiment, which is a waste of time and storage. It would be better to discard the log_dir from the inception_path. Then the inception model will be cached and reused for all experiments.

SSGAN missed Self-Modulation Normalization?

Hi! Thank you for creating this easy-to-use library!

I was using your implementation of SSGAN to reproduce the original paper https://arxiv.org/abs/1810.01365.

As I read the original paper, the highest performing model was the one that used Self-Modulation Normalization, not Batch Normalization like your GBlock https://github.com/kwotsin/mimicry/blob/master/torch_mimicry/modules/resblocks.py#L73.

image

image

Do you have any plans to add Self-Modulation Normalization?

Would it be possible to choose Upsample and Downsample strategies?

Looking at the official BigGAN implementation in Tensorflow, I found they use ConvTranspose2d for Upsample and Conv2d for Downsample in the ResNet block (e.g. https://github.com/taki0112/BigGAN-Tensorflow/blob/master/ops.py#L159).

I know that BigGAN implementations in PyTorch use a combination of Pooling and Conv (e.q. https://github.com/ajbrock/BigGAN-PyTorch/blob/master/BigGAN.py#L341), but in my experience, I can't say for sure which is the better performance.

In the future, is it possible to flexibly select an operation to change the resolution of the input feature map?

Not an issue with the code, but the documentation

"From the paper, for the exact training hyperparameters, the FID is reported to be 17.88 ± 0.64, whereas we achieved 17.77 ± 0.21 so our result is very close!"

Correct me if I am wrong, but isn't the FID the lower the better? So you actually beat the SOTA, I think. Great work by the way!

Custom datasets and location specifications in metrics module

I was wondering if it were possible to add an interface to the metrics.evaluate interface for the following:

  1. Custom datasets: being able to pass a dataloader argument instead of dataset_name would let us use the same function for new/custom data.

  2. Location: similar to how datasets. load_dataset has a root argument, it would be nice if metrics.evaluate offered the same functionality to choose where to place the data.

Apologies if these are already present somewhere. Thanks again for a very nice library.

How to add a new module or net in this repo

Hi, thank your sharing , and I want to add some net or module for testing ,like MSGAN architect, Eql Conv ,and so on。 How should I do ??

I see you recommand pip install , but I do not know if I add same new, what should I do or do nothing??

Are there any plans to develop a distributed version?

Hi! Thank you for your great contribution to this repo. Actually I found it really convenient to reproduce various GANs with the help of mimicry.

However, when I read the code in the training part of the examples, I found it might work well for single GPU scenario but some how not quite suitable for distributed training. I had a glance at the source code of Logger, which enables the visualization using tensorboard, and it turns out that if one adopted distributed training with torch.nn.parallel.DistributedDataParallel, each process(one process for one GPU) will create a new file to record the information of that GPU/process. Apparently, this is not what we want. A possible solution is to create a Tensorboard file only if that process is rank 0 and only to record the average metric. If you are going to improve this, refer to torch.distributed and see the example of imagenet training given by official Pytorch.

Could you add the support for torch >= 1.8?

I am trying to develop a GAN model and I found your library very useful (thanks btw). However, it seems that it's not compatible with the new versions of the torch. And that's a problem for me since many complex number tools are developed for the new version.
Thanks.

Working for non-Linux platforms

I haven't tested whether this library works on Windows and Mac OS machines, and so will have to try them out and check for compatibility.

ImportError: cannot import name 'PY3' from 'torch._six'

When I run

python -c "import torch_mimicry as mmc"

with torch-mimicry==0.1.16 and pytorch==1.12.1, I met the following error:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/root/miniconda3/envs/losthub/lib/python3.9/site-packages/torch_mimicry/__init__.py", line 1, in <module>
    from torch_mimicry import nets, training, metrics, datasets, modules
  File "/root/miniconda3/envs/losthub/lib/python3.9/site-packages/torch_mimicry/metrics/__init__.py", line 2, in <module>
    from .compute_fid import *
  File "/root/miniconda3/envs/losthub/lib/python3.9/site-packages/torch_mimicry/metrics/compute_fid.py", line 12, in <module>
    from torch_mimicry.datasets.image_loader import get_dataset_images
  File "/root/miniconda3/envs/losthub/lib/python3.9/site-packages/torch_mimicry/datasets/__init__.py", line 1, in <module>
    from . import imagenet
  File "/root/miniconda3/envs/losthub/lib/python3.9/site-packages/torch_mimicry/datasets/imagenet/__init__.py", line 1, in <module>
    from .imagenet import *
  File "/root/miniconda3/envs/losthub/lib/python3.9/site-packages/torch_mimicry/datasets/imagenet/imagenet.py", line 14, in <module>
    from .imagenet_utils import check_integrity, download_and_extract_archive, extract_archive, \
  File "/root/miniconda3/envs/losthub/lib/python3.9/site-packages/torch_mimicry/datasets/imagenet/imagenet_utils.py", line 13, in <module>
    from torch._six import PY3
ImportError: cannot import name 'PY3' from 'torch._six' (/root/miniconda3/envs/losthub/lib/python3.9/site-packages/torch/_six.py)

After I checked the _six.py script, I found that this script doesn't import any module named PY3. And in imagenet_utils.py, PY3 is used to do some sort of condition checking e.g.

    elif _is_tarxz(from_path) and PY3:
        # .tar.xz archive only supported in Python 3.x
        with tarfile.open(from_path, 'r:xz') as tar:
            tar.extractall(path=to_path)

I hope that the developer can fix this issue.

[CelebA]RuntimeError: The daily quota of the file img_align_celeba.zip is exceeded and it can't be downloaded. This is a limitation of Google Drive and can only be overcome by trying again later.

I have purchased the most expensive one google colab monthly service. After trying it keeps saying this data is too big. The cifar10 dataset is fine.
I tried another remote gpu that I rented and found the same problem. How can I solve this problem?
(ps:I was under the impression that I had successfully run it once before with google colab.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.