zyddnys / manga-image-translator

Translate manga/image 一键翻译各类图片内文字 https://cotrans.touhou.ai/
https://cotrans.touhou.ai/
GNU General Public License v3.0
5.05k stars 523 forks source link

Assistance in training manga-colorization. #378

Closed My12123 closed 1 year ago

My12123 commented 1 year ago

https://github.com/qweasdd/manga-colorization

(manga-colorization) M:\manga-colorization>python train.py -g -p M:\manga-colorization\train
Traceback (most recent call last):
  File "train.py", line 281, in <module>
    train_dataloader, ft_dataloader = get_dataloaders(args.path, augmentations, config['batch_size'], args.fine_tuning, config['number_of_mults'])
  File "train.py", line 38, in get_dataloaders
    return train_dataloader, finetuning_dataloader
UnboundLocalError: local variable 'finetuning_dataloader' referenced before assignment

How to fix it?

Dependencies that I used: albumentations==1.3.0

My12123 commented 1 year ago
(manga-colorization) M:\manga-colorization>python train.py -g -p M:\manga-colorization\train -ft
14:23:27.140696
Step : 0 Discr loss: 0.0000 Gen loss : 0.0000

14:23:29.842934
Epoch : 0 Discr loss: 1.3872 Gen loss : 0.0000

14:23:29.945935
Step : 0 Discr loss: 0.0000 Gen loss : 0.0000

14:23:30.525580
Epoch : 1 Discr loss: 0.0000 Gen loss : 17.9444

14:23:30.648579
Step : 0 Discr loss: 0.0000 Gen loss : 0.0000

14:23:31.069186
Epoch : 2 Discr loss: 1.3857 Gen loss : 0.0000

14:23:31.181184
Step : 0 Discr loss: 0.0000 Gen loss : 0.0000

14:23:31.699809
Epoch : 3 Discr loss: 0.0000 Gen loss : 17.6327

14:45:10.801170
Epoch : 57 Discr loss: 0.0000 Gen loss : 17.5885

14:45:10.894171
Step : 0 Discr loss: 0.0000 Gen loss : 0.0000

14:45:11.285168
Epoch : 58 Discr loss: 1.3492 Gen loss : 0.0000

14:45:11.376167
Step : 0 Discr loss: 0.0000 Gen loss : 0.0000

14:45:11.809167
Epoch : 59 Discr loss: 0.0000 Gen loss : 16.6267

Traceback (most recent call last):
  File "train.py", line 294, in <module>
    torch.save(colorizer.generator.state_dict(), str(datetime.datetime.now().time()))
  File "F:\1\envs\manga-colorization\lib\site-packages\torch\serialization.py", line 361, in save
    with _open_file_like(f, 'wb') as opened_file:
  File "F:\1\envs\manga-colorization\lib\site-packages\torch\serialization.py", line 229, in _open_file_like
    return _open_file(name_or_buffer, mode)
  File "F:\1\envs\manga-colorization\lib\site-packages\torch\serialization.py", line 210, in __init__
    super(_open_file, self).__init__(open(name, mode))
OSError: [Errno 22] Invalid argument: '14:45:12.292166'
Traceback (most recent call last):
  File "train.py", line 294, in <module>
    torch.save(colorizer.generator.state_dict(), str(datetime.datetime.now().time()))
  File "F:\1\envs\manga-colorization\lib\site-packages\torch\serialization.py", line 361, in save
    with _open_file_like(f, 'wb') as opened_file:
  File "F:\1\envs\manga-colorization\lib\site-packages\torch\serialization.py", line 229, in _open_file_like
    return _open_file(name_or_buffer, mode)
  File "F:\1\envs\manga-colorization\lib\site-packages\torch\serialization.py", line 210, in __init__
    super(_open_file, self).__init__(open(name, mode))
OSError: [Errno 22] Invalid argument: '14:45:12.292166'

How to fix it?

Omicronlawful commented 1 year ago

Use Linux or figure out what Windows file naming rules are.

Btw you are in the wrong repo. This issue does not belong here

My12123 commented 1 year ago

OSError: [Errno 22] Invalid argument: '14:45:12.292166' What needs to be changed to work on Windows?

torch.save(colorizer.generator.state_dict(), str(datetime.datetime.now().time()))
tak2hu commented 1 year ago

OSError: [Errno 22] Invalid argument: '14:45:12.292166'

This looks like coming from datetime.datetime.now().time() (probably idk haven’t tested it)

On Windows, : is an illegal character for a filename (again probably haven’t tested it myself)

Just change torch.save(colorizer.generator.state_dict(), str(datetime.datetime.now().time())) into something like torch.save(colorizer.generator.state_dict(),str(whatever_for_a_checkpoint_filename))

I just remembered about : in Windows filenames are data streams from this YouTube video. Also check out this article and this blog.

Omicronlawful commented 1 year ago

I’m interested how you got the model from v1 working with v2

My12123 commented 1 year ago

This is V1 https://github.com/qweasdd/manga-colorization

Omicronlawful commented 1 year ago

Noticed that, but this project is using v2 which is an improved version of v1

My12123 commented 1 year ago

OSError: [Errno 22] Invalid argument: '14:45:12.292166'

This looks like coming from datetime.datetime.now().time() (probably idk haven’t tested it)

On Windows, : is an illegal character for a filename (again probably haven’t tested it myself)

Just change torch.save(colorizer.generator.state_dict(), str(datetime.datetime.now().time())) into something like torch.save(colorizer.generator.state_dict(),str(whatever_for_a_checkpoint_filename))

I just remembered about : in Windows filenames are data streams from this YouTube video. Also check out this article and this blog.

@tak2hu It didn't help.

(manga-colorization) F:\manga-colorization>python train.py -g -p ./train -ft
19:32:30.383301
Step : 0 Discr loss: 0.0000 Gen loss : 0.0000

19:32:42.473506
Epoch : 0 Discr loss: 1.3900 Gen loss : 0.0000

19:32:42.684518
Step : 0 Discr loss: 0.0000 Gen loss : 0.0000

19:32:43.494637
Epoch : 1 Discr loss: 0.0000 Gen loss : 14.8941

19:32:43.727758
Step : 0 Discr loss: 0.0000 Gen loss : 0.0000

19:32:44.158929
Epoch : 2 Discr loss: 1.3888 Gen loss : 0.0000

19:32:44.365930
Step : 0 Discr loss: 0.0000 Gen loss : 0.0000

19:32:45.108161
Epoch : 3 Discr loss: 0.0000 Gen loss : 18.3954

19:32:45.346162
Step : 0 Discr loss: 0.0000 Gen loss : 0.0000
19:32:51.401488
Epoch : 11 Discr loss: 0.0000 Gen loss : 20.1612

19:32:51.605481
Step : 0 Discr loss: 0.0000 Gen loss : 0.0000

19:32:52.024559
Epoch : 12 Discr loss: 1.3793 Gen loss : 0.0000

19:32:52.237559
Step : 0 Discr loss: 0.0000 Gen loss : 0.0000

19:32:52.806716
Epoch : 13 Discr loss: 0.0000 Gen loss : 15.1746

19:32:53.026233
Step : 0 Discr loss: 0.0000 Gen loss : 0.0000

19:32:53.423234
Epoch : 14 Discr loss: 1.3789 Gen loss : 0.0000

Traceback (most recent call last):
  File "train.py", line 294, in <module>
    torch.save(colorizer.generator.state_dict(),str(whatever_for_a_checkpoint_filename))
NameError: name 'whatever_for_a_checkpoint_filename' is not defined
Omicronlawful commented 1 year ago

Variables need to be defined before usage. Btw why are you training this?

My12123 commented 1 year ago

To make a better coloring model, but I don't know if it will work.

Omicronlawful commented 1 year ago

Training will work, but you should try using the improved version and training a model for that, cuz improved == better.

My12123 commented 1 year ago

@Omicronlawful In version V2, learning is impossible.

My12123 commented 1 year ago

@tak2hu Will there be an answer to this?

OSError: [Errno 22] Invalid argument: '14:45:12.292166' This looks like coming from datetime.datetime.now().time() (probably idk haven’t tested it) On Windows, : is an illegal character for a filename (again probably haven’t tested it myself) Just change torch.save(colorizer.generator.state_dict(), str(datetime.datetime.now().time())) into something like torch.save(colorizer.generator.state_dict(),str(whatever_for_a_checkpoint_filename)) I just remembered about : in Windows filenames are data streams from this YouTube video. Also check out this article and this blog.

@tak2hu It didn't help.

(manga-colorization) F:\manga-colorization>python train.py -g -p ./train -ft
19:32:30.383301
Step : 0 Discr loss: 0.0000 Gen loss : 0.0000

19:32:42.473506
Epoch : 0 Discr loss: 1.3900 Gen loss : 0.0000

19:32:42.684518
Step : 0 Discr loss: 0.0000 Gen loss : 0.0000

19:32:43.494637
Epoch : 1 Discr loss: 0.0000 Gen loss : 14.8941

19:32:43.727758
Step : 0 Discr loss: 0.0000 Gen loss : 0.0000

19:32:44.158929
Epoch : 2 Discr loss: 1.3888 Gen loss : 0.0000

19:32:44.365930
Step : 0 Discr loss: 0.0000 Gen loss : 0.0000

19:32:45.108161
Epoch : 3 Discr loss: 0.0000 Gen loss : 18.3954

19:32:45.346162
Step : 0 Discr loss: 0.0000 Gen loss : 0.0000
19:32:51.401488
Epoch : 11 Discr loss: 0.0000 Gen loss : 20.1612

19:32:51.605481
Step : 0 Discr loss: 0.0000 Gen loss : 0.0000

19:32:52.024559
Epoch : 12 Discr loss: 1.3793 Gen loss : 0.0000

19:32:52.237559
Step : 0 Discr loss: 0.0000 Gen loss : 0.0000

19:32:52.806716
Epoch : 13 Discr loss: 0.0000 Gen loss : 15.1746

19:32:53.026233
Step : 0 Discr loss: 0.0000 Gen loss : 0.0000

19:32:53.423234
Epoch : 14 Discr loss: 1.3789 Gen loss : 0.0000

Traceback (most recent call last):
  File "train.py", line 294, in <module>
    torch.save(colorizer.generator.state_dict(),str(whatever_for_a_checkpoint_filename))
NameError: name 'whatever_for_a_checkpoint_filename' is not defined
Omicronlawful commented 1 year ago

@My12123 v2 is based on v1 so the model would work with minor changes. Look at the generators. He changed the python encoder blocks and the feature_conv got removed while an encoder was added instead. The rest is the same.

variables still need to be defined before usage to work

https://github.com/qweasdd/manga-colorization-v2/blob/master/networks/models.py#L185 https://github.com/qweasdd/manga-colorization/blob/master/model/models.py#L183

Omicronlawful commented 1 year ago

Btw why aren’t you trying to train deoldify as suggested in #360. This repoaity is still maintained and you could ask there for specific help

My12123 commented 1 year ago

@Omicronlawful https://github.com/Dakini/AnimeColorDeOldify An error occurred while working https://github.com/Dakini/AnimeColorDeOldify/issues/9

Omicronlawful commented 1 year ago

That’s a 2 year old fork of deoldify. With nogan of courses. I think the links can be found in #360

tak2hu commented 1 year ago

@tak2hu It didn't help.

Bruh define that variable yourself or just use a string like “mysavedmodel.pth” in place of str(whatever_for_a_checkpoint_filename).

I advise you to learn more (on how to modify someone else’s) python (project to suit your needs and environment). One step at a time.

Omicronlawful commented 1 year ago

But it sucks so why would you run it. If you want good results you need to train the newer architecture with Nogan.

Keiser04 commented 11 months ago

how do you can train?

My12123 commented 11 months ago

@Keiser04 It is not possible to complete the training specifically to save the model.

Keiser04 commented 11 months ago

but how did you get there? it's just that this bw thing I mentioned before is a problem and I can't investigate further so if you could help me (I'm working on collab) @My12123

My12123 commented 11 months ago

@Keiser04 I installed on windows. Run the following commands to install

python -m venv venv
call .\venv\Scripts\activate
pip install -r requirements.txt

The instruction is not complete

My12123 commented 11 months ago

@Keiser04 Can you describe the error in more detail?

Keiser04 commented 11 months ago

imagen maybe it's because of this but basically the error is something like this. i have 3 folders, color, real_manga and bw. the datasets.py is executed once the train.py is executed which in theory converts the images from ccolor to black and white, but it doesn't. and the worst thing is that it looks for the files in theory generated.

Keiser04 commented 11 months ago

i use your requeriments but i can't create a build due to matplotlib error imagen

My12123 commented 11 months ago

@Keiser04 https://github.com/qweasdd/manga-colorization/issues/2#issuecomment-1777182817 You need to create color and black and white yourself. see the link. I do this when I had python 3.6 and it's better to use anaconda then there will be fewer possible errors. datasets does not make significant changes, it only renames the color and black-and-white photo files and puts them in a special folder.

Keiser04 commented 11 months ago

imagen this is my error. it is as if it was looking for the files in bw, but it adds for example "_0" to the file name. the problem is that it is random, now I will try with the first version of the training.

Keiser04 commented 11 months ago

do you know what i can do? i try so much but still serching for an archive whit wrong name

My12123 commented 11 months ago

@Keiser04 Now I tried to install it, but I ran into an error

Traceback (most recent call last):
  File "F:\manga-colorization\dataset\datasets.py", line 7, in <module>
    from utils.utils import generate_mask
ModuleNotFoundError: No module named 'utils.utils'
Keiser04 commented 11 months ago

I got it too, it's a problem when trying to import the folder, you can do it by deleting untils.untils and leaving it as untils in training or specify the location.

Keiser04 commented 11 months ago

@My12123 this are the versions of the program https://github.com/qweasdd/manga-colorization/commits/master

Keiser04 commented 11 months ago

This is my error, it comes from dataset.py

Train Dataset Length: 8
FineTuning Dataset Length: 8
Traceback (most recent call last):
  File "/content/manga-colorization/train.py", line 292, in <module>
    train(colorizer, discriminator, content, train_dataloader, config['epochs'], gen_optimizer, disc_optimizer, config['lr_decrease_epoch'], device)
  File "/content/manga-colorization/train.py", line 174, in train
    for n, inputs in enumerate(dataloader):
  File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/dataloader.py", line 630, in __next__
    data = self._next_data()
  File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/dataloader.py", line 674, in _next_data
    data = self._dataset_fetcher.fetch(index)  # may raise StopIteration
  File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/_utils/fetch.py", line 51, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/_utils/fetch.py", line 51, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/content/manga-colorization/dataset/datasets.py", line 37, in __getitem__
    bw_img =  np.expand_dims(plt.imread(os.path.join(self.data_path, 'bw', bw_name)), 2)
  File "/usr/local/lib/python3.10/dist-packages/matplotlib/pyplot.py", line 2389, in imread
    return matplotlib.image.imread(fname, format)
  File "/usr/local/lib/python3.10/dist-packages/matplotlib/image.py", line 1525, in imread
    with img_open(fname) as image:
  File "/usr/local/lib/python3.10/dist-packages/PIL/ImageFile.py", line 105, in __init__
    self.fp = open(fp, "rb")
FileNotFoundError: [Errno 2] No such file or directory: '/content/manga-colorization/dataset/train/bw/a (6)_2.png'
My12123 commented 11 months ago

@Keiser04 I did not have such an error, this error is that python does not find the file.

Train Dataset Length: 8 FineTuning Dataset Length: 8 Traceback (most recent call last): File "/content/manga-colorization/train.py", line 292, in train(colorizer, discriminator, content, train_dataloader, config['epochs'], gen_optimizer, disc_optimizer, config['lr_decrease_epoch'], device) File "/content/manga-colorization/train.py", line 174, in train for n, inputs in enumerate(dataloader): File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/dataloader.py", line 630, in next data = self._next_data() File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/dataloader.py", line 674, in _next_data data = self._dataset_fetcher.fetch(index) # may raise StopIteration File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/_utils/fetch.py", line 51, in fetch data = [self.dataset[idx] for idx in possibly_batched_index] File "/usr/local/lib/python3.10/dist-packages/torch/utils/data/_utils/fetch.py", line 51, in data = [self.dataset[idx] for idx in possibly_batched_index] File "/content/manga-colorization/dataset/datasets.py", line 37, in getitem bw_img = np.expand_dims(plt.imread(os.path.join(self.data_path, 'bw', bw_name)), 2) File "/usr/local/lib/python3.10/dist-packages/matplotlib/pyplot.py", line 2389, in imread return matplotlib.image.imread(fname, format) File "/usr/local/lib/python3.10/dist-packages/matplotlib/image.py", line 1525, in imread with img_open(fname) as image: File "/usr/local/lib/python3.10/dist-packages/PIL/ImageFile.py", line 105, in init self.fp = open(fp, "rb") FileNotFoundError: [Errno 2] No such file or directory: '/content/manga-colorization/dataset/train/bw/a (6)_2.png'

Create this file a (6)_2.png

I have.

(Manga_Colorization) F:\manga-colorization>python F:\manga-colorization\dataset\datasets.py
Traceback (most recent call last):
  File "F:\manga-colorization\dataset\datasets.py", line 7, in <module>
    from utils import generate_mask
ImportError: cannot import name 'generate_mask'

Do you know how to fix something I don't remember anymore?

Keiser04 commented 11 months ago

Type, it doesn't matter if you create the file or not or rename it, because the number after the "_" is a random one. I mean I tried it and at least in my case it was like that. That said, what name do you have the main folder with?
@My12123

Keiser04 commented 11 months ago

Or in the training file delete the untils.untils and replace it by untils

OR

import sys sys.path.append('path_of_the_folder_untils')

Keiser04 commented 10 months ago

Do you still have the dataset? the training is more or less working for me. @My12123

My12123 commented 10 months ago

@Keiser04 Not anymore, but it can be created. If you need help in creating, write. I am currently trying to run this repository https://github.com/Atharva-Phatak/Manga-Colorizer#streamlit-app-and-onnx-conversion the author seems to have forgotten to answer me and then stopped https://github.com/Atharva-Phatak/Manga-Colorizer/issues/5

Keiser04 commented 10 months ago

Yes, if you can.... i have this error, the error that looks for more images is due to the fact that the configs file clarifies how many examples there are of each image, just change it from 1 to 3. I changed an image processor for a more current one and it worked but it stays there. imagen

Keiser04 commented 10 months ago

is that a local web app? I know more or less how to train a pix model although I never tried it, I have the collab if you want it. @My12123

My12123 commented 10 months ago

@Keiser04 Yes I do. Can you help me figure out the data set and training in this repository https://github.com/Atharva-Phatak/Manga-Colorizer / and help with these problems.

Keiser04 commented 10 months ago

Can you sendme a exemple of dataset please??? My mail is sae89413@gmail.com. Or send me the link here

This is the git of the training https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix

And this the colab https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix/blob/master/pix2pix.ipynb

But we need to see what model it uses for it