Coder Social home page Coder Social logo

lornatang / cyclegan-pytorch Goto Github PK

View Code? Open in Web Editor NEW
139.0 7.0 32.0 1.48 MB

A very simple implementation of cyclegan, which is based on pytorch.

Home Page: https://arxiv.org/abs/1703.10593

License: Apache License 2.0

Python 100.00%
generative-adversarial-networks deep-learning cyclegan computer-vision

cyclegan-pytorch's Introduction

CycleGAN-PyTorch

Overview

This repository contains an op-for-op PyTorch reimplementation of Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks.

Table of contents

Download weights

Download datasets

Please refer to README.md in the data directory for the method of making a dataset.

Train CycleGAN-apple2orange

python3 train.py --config_path ./configs/CYCLEGAN.yaml

Resume train CycleGAN-apple2orange

Modify the ./configs/CYCLEGAN.yaml file.

  • line 43: LOAD_RESUME change to True.
  • line 44: RESUME_G_A_MODEL_WEIGHTS_PATH change to samples/CycleGAN-apple2orange/g_A_epoch_XXX.pth.tar.
  • line 45: RESUME_G_B_MODEL_WEIGHTS_PATH change to samples/CycleGAN-apple2orange/g_B_epoch_XXX.pth.tar.
  • line 46: RESUME_D_A_MODEL_WEIGHTS_PATH change to samples/CycleGAN-apple2orange/d_A_epoch_XXX.pth.tar.
  • line 47: RESUME_D_B_MODEL_WEIGHTS_PATH change to samples/CycleGAN-apple2orange/d_B_epoch_XXX.pth.tar.
python3 train.py --config_path ./configs/CYCLEGAN.yaml

Result

InputA --> StyleB --> RecoveryA

Contributing

If you find a bug, create a GitHub issue, or even better, submit a pull request. Similarly, if you have questions, simply post them as GitHub issues.

I look forward to seeing what the community does with these models!

Credit

Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networks

Jun-Yan Zhu, Taesung Park, Phillip Isola, Alexei A. Efros

Abstract
Image-to-image translation is a class of vision and graphics problems where the goal is to learn the mapping between an input image and an output image using a training set of aligned image pairs. However, for many tasks, paired training data will not be available. We present an approach for learning to translate an image from a source domain X to a target domain Y in the absence of paired examples. Our goal is to learn a mapping G:X→Y such that the distribution of images from G(X) is indistinguishable from the distribution Y using an adversarial loss. Because this mapping is highly under-constrained, we couple it with an inverse mapping F:Y→X and introduce a cycle consistency loss to push F(G(X))≈X (and vice versa). Qualitative results are presented on several tasks where paired training data does not exist, including collection style transfer, object transfiguration, season transfer, photo enhancement, etc. Quantitative comparisons against several prior methods demonstrate the superiority of our approach.

[Paper]) [Code(PyTorch)]

@inproceedings{CycleGAN2017,
  title={Unpaired Image-to-Image Translation using Cycle-Consistent Adversarial Networkss},
  author={Zhu, Jun-Yan and Park, Taesung and Isola, Phillip and Efros, Alexei A},
  booktitle={Computer Vision (ICCV), 2017 IEEE International Conference on},
  year={2017}
}

cyclegan-pytorch's People

Contributors

bfirsh avatar dependabot[bot] avatar kaminyou avatar lornatang 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

cyclegan-pytorch's Issues

Can't find a weight folder

there is no 'weight folder' in the project list, I can't use 'bash download_weights.sh horse2zebra'or '.\download_weights.bat horse2zebra' in the terminal. Please somebody help

Error in file get_dataset.sh

"&&" in start of array

if [[ && ${FILE} != "apple2orange" && ${FILE} != "summer2winter_yosemite" &&  ${FILE} != "horse2zebra" && ${FILE} != "monet2photo" && ${FILE} != "cezanne2photo" && ${FILE} != "ukiyoe2photo" && ${FILE} != "vangogh2photo" && ${FILE} != "maps" && ${FILE} != "facades" && ${FILE} != "iphone2dslr_flower" ]]; then
    echo "Available datasets are: apple2orange, summer2winter_yosemite, horse2zebra, monet2photo, cezanne2photo, ukiyoe2photo, vangogh2photo, maps, cityscapes, facades, iphone2dslr_flower"
    exit 1

Nee remove && at start

if [[ && ${FILE} --> if [[ ${FILE}

if [[ ${FILE} != "apple2orange" && ${FILE} != "summer2winter_yosemite" &&  ${FILE} != "horse2zebra" && ${FILE} != "monet2photo" && ${FILE} != "cezanne2photo" && ${FILE} != "ukiyoe2photo" && ${FILE} != "vangogh2photo" && ${FILE} != "maps" && ${FILE} != "facades" && ${FILE} != "iphone2dslr_flower" ]]; then
    echo "Available datasets are: apple2orange, summer2winter_yosemite, horse2zebra, monet2photo, cezanne2photo, ukiyoe2photo, vangogh2photo, maps, cityscapes, facades, iphone2dslr_flower"
    exit 1

Custom Dataset + creating multiple samples

Hi,
Can I use this on my custom dataset - the dataset converts sunny images to indoor lighting images. I have the data is the format - sunny2normal with trainA, trainB, testA and testB inside it
Also I want to generate 1000 samples of sunny images converted by the model to normal, is that possible and how?

RuntimeError: output with shape [1, 256, 256] doesn't match the broadcast shape [3, 256, 256]

i met this error
Traceback (most recent call last):
File "train.py", line 164, in
for i, data in progress_bar:
File "/home/hoang/anaconda3/envs/cyclegan/lib/python3.6/site-packages/tqdm/std.py", line 1195, in iter
for obj in iterable:
File "/home/hoang/anaconda3/envs/cyclegan/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 521, in next
data = self._next_data()
File "/home/hoang/anaconda3/envs/cyclegan/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 561, in _next_data
data = self._dataset_fetcher.fetch(index) # may raise StopIteration
File "/home/hoang/anaconda3/envs/cyclegan/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 49, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/home/hoang/anaconda3/envs/cyclegan/lib/python3.6/site-packages/torch/utils/data/utils/fetch.py", line 49, in
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/home/hoang/Desktop/luanvan/cycleGAN/CycleGAN-PyTorch/cyclegan_pytorch/datasets.py", line 38, in getitem
item_B = self.transform(Image.open(self.files_B[random.randint(0, len(self.files_B) - 1)]))
File "/home/hoang/anaconda3/envs/cyclegan/lib/python3.6/site-packages/torchvision/transforms/transforms.py", line 61, in call
img = t(img)
File "/home/hoang/anaconda3/envs/cyclegan/lib/python3.6/site-packages/torch/nn/modules/module.py", line 1102, in call_impl
return forward_call(*input, **kwargs)
File "/home/hoang/anaconda3/envs/cyclegan/lib/python3.6/site-packages/torchvision/transforms/transforms.py", line 226, in forward
return F.normalize(tensor, self.mean, self.std, self.inplace)
File "/home/hoang/anaconda3/envs/cyclegan/lib/python3.6/site-packages/torchvision/transforms/functional.py", line 351, in normalize
tensor.sub
(mean).div
(std)
RuntimeError: output with shape [1, 256, 256] doesn't match the broadcast shape [3, 256, 256]

How to train with multiple gpu

Thanks for sharing the code. I'm realizing the training on top of my own PC (only one Nvidia 3060), but it's difficult to change it to multiple GPUs (3090*4) training on the server

question about data range

image
The range of data from datasets is between [0,1].
While the range of data which is generated from generator is between [-1,1].
image

How can these two ranges compare with each other? Is there something wrong or I made some mitakes? Can anyone help me?

image

time.clock() deprecated in python

time.clock() has been removed in python, causing test_image.py to crash. It has been replaced with timeit.default_timer.
It can be fixed with sed -i 's/time\.clock/timeit\.default_timer/g' test_image.py.

A question about data type

I just run train.py without changing. The error report shows information below.
Traceback (most recent call last):
File "D:/research/noofficial_cyclegan/cyclegan-pytorch-master/train.py", line 32, in
from dataset import CUDAPrefetcher, ImageDataset
File "D:\research\noofficial_cyclegan\cyclegan-pytorch-master\dataset.py", line 25, in
from imgproc import image_to_tensor, random_rotate, random_horizontally_flip, random_vertically_flip
File "D:\research\noofficial_cyclegan\cyclegan-pytorch-master\imgproc.py", line 150, in
center: tuple[int, int] = None,
TypeError: 'type' object is not subscriptable

Is my python version wrong? Thank you for answering.

TypeError: unsupported operand type(s) for |: 'type' and 'torch._C._TensorMeta'

hi, I hope your help. Thanks!
error
python3 train.py --config_path ./configs/CYCLEGAN.yaml

Traceback (most recent call last):
  File "train.py", line 38, in <module>
    from dataset import CUDAPrefetcher, ImageDataset
  File "/home/image1325_user/ssd_disk2/yudongjian_23/CycleGAN-PyTorch-master/dataset.py", line 25, in <module>
    from imgproc import image_to_tensor
  File "/home/image1325_user/ssd_disk2/yudongjian_23/CycleGAN-PyTorch-master/imgproc.py", line 105, in <module>
    src_images: ndarray | Tensor | list[ndarray] | list[Tensor],
TypeError: unsupported operand type(s) for |: 'type' and 'torch._C._TensorMeta'

RuntimeError: Tried to instantiate dummy base class Stream

Traceback (most recent call last):
File "E:\lunwen\CycleGAN-PyTorch-88e1f17a8a7be24b982cce16a6cf0db043e13bdc\CycleGAN-PyTorch-88e1f17a8a7be24b982cce16a6cf0db043e13bdc\train.py", line 545, in
main()
File "E:\lunwen\CycleGAN-PyTorch-88e1f17a8a7be24b982cce16a6cf0db043e13bdc\CycleGAN-PyTorch-88e1f17a8a7be24b982cce16a6cf0db043e13bdc\train.py", line 54, in main
train_prefetcher = load_dataset(config.src_image_path,
File "E:\lunwen\CycleGAN-PyTorch-88e1f17a8a7be24b982cce16a6cf0db043e13bdc\CycleGAN-PyTorch-88e1f17a8a7be24b982cce16a6cf0db043e13bdc\train.py", line 240, in load_dataset
train_prefetcher = CUDAPrefetcher(train_dataloader, device)
File "E:\lunwen\CycleGAN-PyTorch-88e1f17a8a7be24b982cce16a6cf0db043e13bdc\CycleGAN-PyTorch-88e1f17a8a7be24b982cce16a6cf0db043e13bdc\dataset.py", line 172, in init
self.stream = torch.cuda.Stream()
File "F:\anaconda\envs\cycle\lib\site-packages\torch\cuda\streams.py", line 34, in new
return super().new(cls, priority=priority, **kwargs)
File "F:\anaconda\envs\cycle\lib\site-packages\torch\cuda_utils.py", line 49, in err_fn
raise RuntimeError(f"Tried to instantiate dummy base class {class_name}")
May I ask what the reason is? Is it because I can't find CUDA on my computer? If I only use CPU training, how should I modify the code

"The model is not compiled" when trying to reasume training

Traceback (most recent call last):
  File "...CycleGAN-PyTorch/train.py", line 594, in <module>
    main()
  File ".../CycleGAN-PyTorch/train.py", line 104, in main
    g_A_model, ema_g_A_model, start_epoch, g_optimizer, g_scheduler = load_resume_state_dict(
                                                                      ^^^^^^^^^^^^^^^^^^^^^^^
  File ".../CycleGAN-PyTorch/utils.py", line 137, in load_resume_state_dict
    model = load_state_dict(model, compile_state, state_dict)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../CycleGAN-PyTorch/utils.py", line 60, in load_state_dict
    raise RuntimeError("The model is not compiled. Please use `model = torch.compile(model)`.")
RuntimeError: The model is not compiled. Please use `model = torch.compile(model)`.

Config:

    LOAD_RESUME: True
    RESUME_G_A_MODEL_WEIGHTS_PATH: ./results/CycleGAN-apple2orange/g_A_best.pth.tar
    RESUME_G_B_MODEL_WEIGHTS_PATH: ./results/CycleGAN-apple2orange/g_B_best.pth.tar
    RESUME_D_A_MODEL_WEIGHTS_PATH: ./results/CycleGAN-apple2orange/d_A_best.pth.tar
    RESUME_D_B_MODEL_WEIGHTS_PATH: ./results/CycleGAN-apple2orange/d_B_best.pth.tar

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.