taoxugit/AttnGAN

test on colab

Iam5B opened this issue · 17 comments

Iam5B commented

You may run it in your COLAB notebook to generate some bird pictures.
Notice the annotation.

# -*- coding: utf-8 -*-
"""Untitled3.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1hje6ToTzPYJZx5Fta4KGM4vEfE1D7cRx
"""

!python --version
# python 2.7 with GPU
# after 2020.1 you'll have to download python 2.7 on your own

!git clone https://github.com/taoxugit/AttnGAN.git

!pip install python-dateutil
!pip install easydict
!pip install pandas
!pip install torchfile
!pip install nltk
!pip install scikit-image

%cd AttnGAN/DAMSMencoders/
!wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=1GNUKjVeyWYBJ8hEU-yrfYQpDOkxEyP3V' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=1GNUKjVeyWYBJ8hEU-yrfYQpDOkxEyP3V" -O bird.zip && rm -rf /tmp/cookies.txt
!unzip bird.zip
!wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=1zIrXCE9F6yfbEJIbNP5-YrEe2pZcPSGJ' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=1zIrXCE9F6yfbEJIbNP5-YrEe2pZcPSGJ" -O coco.zip && rm -rf /tmp/cookies.txt
!unzip coco.zip

%cd ../models/
!wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=1lqNG75suOuR_8gjoEPYNp8VyT_ufPPig' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=1lqNG75suOuR_8gjoEPYNp8VyT_ufPPig" -O bird_AttnGAN2.pth && rm -rf /tmp/cookies.txt
!wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=1i9Xkg9nU74RAvkcqKE-rJYhjvzKAMnCi' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=1i9Xkg9nU74RAvkcqKE-rJYhjvzKAMnCi" -O coco_AttnGAN2.pth && rm -rf /tmp/cookies.txt
!wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=19TG0JUoXurxsmZLaJ82Yo6O0UJ6aDBpg' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=19TG0JUoXurxsmZLaJ82Yo6O0UJ6aDBpg" -O bird_AttnDCGAN2.pth && rm -rf /tmp/cookies.txt

%cd ../data/
!wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=1O_LtUP9sch09QH3s_EBAgLEctBQ5JBSJ' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=1O_LtUP9sch09QH3s_EBAgLEctBQ5JBSJ" -O birds.zip && rm -rf /tmp/cookies.txt
!unzip birds.zip

!wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=1rSnbIGNDGZeHlsUlLdahj0RJ9oo6lgH9' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=1rSnbIGNDGZeHlsUlLdahj0RJ9oo6lgH9" -O coco.zip && rm -rf /tmp/cookies.txt
!unzip coco.zip

%cd ./birds/
!unzip text.zip
!wget http://www.vision.caltech.edu/visipedia-data/CUB-200-2011/CUB_200_2011.tgz
!tar zxvf CUB_200_2011.tgz -C ./

%cd ../coco/
!wget http://cocodataset.org/#download
# don't know what to download

%cd ../../code/

#NOTICE in miscc/utils.py line35 should be 'fnt = ImageFont.load_default().font'
#NOTICE in miscc/config.py set TRAIN.FLAG = False

!python main.py --cfg cfg/eval_bird.yml --gpu 0

# the result is located in ../models/AttnGAN2/

@Iam5B thanks for your comment, I need permission to get the code from google cloab. I have tried to run it but I get errors.thanks in advance.

@Iam5B
I am a novice. Where is the output of your colab? I opened the ../models/AttnGAN2/ directory, but I did not find the output image. Hope you can help me.

@Iam5B
I found the reason, the picture is in the / content / AttnGAN / models / bird_AttnGAN2 / Chestnut_Sided_Warbler_0103_163669 directory, I tried to find it after a while, in short, thank you for your help.

Iam5B commented

@Supercrooks
I was just struggling to open COLAB.
It's great that you can find the picture.

How can I generate more sample images, can you tell me about it? @Iam5B

@Iam5B """ when i run the last code , it will appear some error in the follow

"""
/content/drive/My Drive/AttnGAN/code
Using config:
{'B_VALIDATION': False,
'CONFIG_NAME': 'attn2',
'CUDA': True,
'DATASET_NAME': 'birds',
'DATA_DIR': '../data/birds',
'GAN': {'B_ATTENTION': True,
'B_DCGAN': False,
'CONDITION_DIM': 100,
'DF_DIM': 64,
'GF_DIM': 32,
'R_NUM': 2,
'Z_DIM': 100},
'GPU_ID': 0,
'RNN_TYPE': 'LSTM',
'TEXT': {'CAPTIONS_PER_IMAGE': 10, 'EMBEDDING_DIM': 256, 'WORDS_NUM': 25},
'TRAIN': {'BATCH_SIZE': 100,
'B_NET_D': False,
'DISCRIMINATOR_LR': 0.0002,
'ENCODER_LR': 0.0002,
'FLAG': False,
'GENERATOR_LR': 0.0002,
'MAX_EPOCH': 600,
'NET_E': '../DAMSMencoders/bird/text_encoder200.pth',
'NET_G': '../models/bird_AttnGAN2.pth',
'RNN_GRAD_CLIP': 0.25,
'SMOOTH': {'GAMMA1': 5.0,
'GAMMA2': 5.0,
'GAMMA3': 10.0,
'LAMBDA': 1.0},
'SNAPSHOT_INTERVAL': 2000},
'TREE': {'BASE_SIZE': 64, 'BRANCH_NUM': 3},
'WORKERS': 1}
Total filenames: 11788 001.Black_footed_Albatross/Black_Footed_Albatross_0046_18.jpg
Load filenames from: ../data/birds/train/filenames.pickle (8855)
Load filenames from: ../data/birds/test/filenames.pickle (2933)
Load from: ../data/birds/captions.pickle
THCudaCheck FAIL file=/pytorch/aten/src/THC/THCGeneral.cpp line=47 error=100 : no CUDA-capable device is detected
Traceback (most recent call last):
File "main.py", line 136, in
algo = trainer(output_dir, dataloader, dataset.n_words, dataset.ixtoword)
File "/content/drive/My Drive/AttnGAN/code/trainer.py", line 36, in init
torch.cuda.set_device(cfg.GPU_ID)
File "/usr/local/lib/python3.6/dist-packages/torch/cuda/init.py", line 281, in set_device
torch._C._cuda_setDevice(device)
File "/usr/local/lib/python3.6/dist-packages/torch/cuda/init.py", line 190, in _lazy_init
torch._C._cuda_init()
RuntimeError: cuda runtime error (100) : no CUDA-capable device is detected at /pytorch/aten/src/THC/THCGeneral.cpp:47
"""

then i change the vision to torch==1.2.0; torchvision==0.4.0; it will appear the follow error

"""
/content/drive/My Drive/AttnGAN/code
Traceback (most recent call last):
File "main.py", line 4, in
from datasets import TextDataset
File "/content/drive/My Drive/AttnGAN/code/datasets.py", line 14, in
import torchvision.transforms as transforms
File "/usr/local/lib/python3.6/dist-packages/torchvision/init.py", line 2, in
from torchvision import datasets
File "/usr/local/lib/python3.6/dist-packages/torchvision/datasets/init.py", line 9, in
from .fakedata import FakeData
File "/usr/local/lib/python3.6/dist-packages/torchvision/datasets/fakedata.py", line 3, in
from .. import transforms
File "/usr/local/lib/python3.6/dist-packages/torchvision/transforms/init.py", line 1, in
from .transforms import *
File "/usr/local/lib/python3.6/dist-packages/torchvision/transforms/transforms.py", line 17, in
from . import functional as F
File "/usr/local/lib/python3.6/dist-packages/torchvision/transforms/functional.py", line 5, in
from PIL import Image, ImageOps, ImageEnhance, PILLOW_VERSION
ImportError: cannot import name 'PILLOW_VERSION'
"""

can you tell me what should i do .

Iam5B commented

@cainiaoshiwo
1.Replace pip with pip2
2.Replace python with python2
I'm not sure if that would help ...

@Iam5B When I try to use my own datasets, I can got preliminary training model, but in training model, i will be submitted to the following error. then I don't change any parameters and just run again, it will report the same error (for example:error changed to: KeyError: '15CrMoG-CB/19700511-5.jpg' ), but the error of image are changed, the question has bothered me for a long time, Could you tell me how to solve this problem, thank you very much.

“”“
Total filenames: 40 1E0669/19700494-2.jpg
Load filenames from: ../data/birds/train/filenames.pickle (24)
Load filenames from: ../data/birds/test/filenames.pickle (16)
Load from: ../data/birds/captions.pickle
/usr/local/lib/python3.6/dist-packages/torchvision/models/inception.py:77: FutureWarning: The default weight initialization of inception_v3 will be changed in future releases of torchvision. If you wish to keep the old behavior (which leads to long initialization times due to scipy/scipy#11299), please set init_weights=True.
' due to scipy/scipy#11299), please set init_weights=True.', FutureWarning)
Load pretrained model from https://download.pytorch.org/models/inception_v3_google-1a9a5a14.pth
Load image encoder from: ../DAMSMencoders/bird/image_encoder200.pth
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/rnn.py:60: UserWarning: dropout option adds dropout after all but last recurrent layer, so non-zero dropout expects num_layers greater than 1, but got dropout=0.5 and num_layers=1
"num_layers={}".format(dropout, num_layers))
Load text encoder from: ../DAMSMencoders/bird/text_encoder200.pth

of netsD 3

Traceback (most recent call last):
File "main.py", line 140, in
algo.train()
File "/content/drive/My Drive/AttnGAN/code/trainer.py", line 245, in train
data = data_iter.next()
File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py", line 363, in next
data = self._next_data()
File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py", line 989, in _next_data
return self._process_data(data)
File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py", line 1014, in _process_data
data.reraise()
File "/usr/local/lib/python3.6/dist-packages/torch/_utils.py", line 395, in reraise
raise self.exc_type(msg)
KeyError: Caught KeyError in DataLoader worker process 0.
Original Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/worker.py", line 185, in _worker_loop
data = fetcher.fetch(index)
File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/fetch.py", line 44, in
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/content/drive/My Drive/AttnGAN/code/datasets.py", line 295, in getitem
bbox = self.bbox[key]
KeyError: '15CrMoG-CB/19700511-1.jpg'
”“”

Iam5B commented

@cainiaoshiwo look at my profile

@Iam5B yes , I have seen your profile, and I have configured my datasets according to your profile , but I don't know what went wrong. The above error description always occurs. Is it because there is something wrong with my datasets(i don't know)? could you have any methods to solve this error?

@Iam5B By the way, I'm running the program in python3.0 (someone else is shared in the latter), is that a problem?

Iam5B commented

I mean you can send e-mail. @cainiaoshiwo

Liqq1 commented

I mean you can send e-mail. @cainiaoshiwo

hello,the link is broken,could i get a new one?thank!

Sorry, can not open the colab link