kwotsin / mimicry Goto Github PK
View Code? Open in Web Editor NEW[CVPR 2020 Workshop] A PyTorch GAN library that reproduces research results for popular GANs.
License: MIT License
[CVPR 2020 Workshop] A PyTorch GAN library that reproduces research results for popular GANs.
License: MIT License
Hi @kwotsin!
Awesome work with this repo! Would it be possible for you to release the pre-trained discriminators too?
the Example outputs without the detail of Fid
I can only see this:
INFO: FID Evaluation completed!
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!
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'):
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
How did u resize the images to 128x128? want some details!🙏
I was wondering if you could clarify some evaluation details for the models/datasets listed in the readme tables. In particular:
Which training splits were used (e.g., "train" for training and "test" for testing, "all" for both, etc...)?
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!
Hi, I see your code, including many tensorflow used ,such as
compute_fid
, compute_kid
, compute_inception_score
, and so on
Would you plan to update pytorch code for those function??
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!
Hi, will it be possible to generate some images to make some visual checks of the network performances?
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)?
Thanks for your code!! I want to do some research on SNGAN, can you provide the discriminator weights of SNGAN on celeba 64x64 dataset? Thanks a lot!
windows10
python3.7
torch 1.7
torchvision 0.8
RuntimeError: Expected tensor for argument #1 'indices' to have scalar type Long; but got torch.cuda.IntTensor instead (while checking arguments for embedding)
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
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.
I'm trying to implement the self-attention for 256x256 size image but it didn't work well.
I've tried many times.
Thanks in advance.
Thanks for this excellent work!
But I met one problem to train DCgan on CIFAR10. Could you please to give me some details of this configs of training?
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.
Do you have any plans to add Self-Modulation Normalization?
The read the docs webpage contains the wrong documentation for the training.Trainer
class. Currently the documentation displayed is that of the training.Logger
class.
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?
Great repository! any plans on adding SAGAN (https://arxiv.org/pdf/1805.08318.pdf)?
Thanks
In cgan-pd-32.py, line 124:
if y is None: y = self.generate_labels(x.shape[0], device=x.device)
Where can I find the method generate_labels
?
ImageNet token is empty. Please obtain permission token from the official website.
what happened?
I want to try to modify the loss function of the sngan discriminator
I deleted some base net files and found that it(example.py) works too.
"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!
Hi, this progress is very slow and maybe it only using CPU for computiing!!!
(2~3 sec/batch) can you update it for GPU using?
I was wondering if it were possible to add an interface to the metrics.evaluate
interface for the following:
Custom datasets: being able to pass a dataloader
argument instead of dataset_name
would let us use the same function for new/custom data.
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.
Thank you for your hard work on this library!
Do you have any plans to add StyleGAN(2)? There are unofficial numerous PyTorch implementations (e.g. https://github.com/rosinality/stylegan2-pytorch) on GitHub.
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??
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.
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.
Would maintainers consider switching to https://github.com/toshas/torch-fidelity for Inception-induced score/metrics?
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.
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.
On the LSUN dataset, the FID score of SNGAN is 25.87, while others are about 12.
What do you think of this gap?
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.)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.