Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typo in model.py #8

Open
MrtnStnwk opened this issue Jun 26, 2019 · 4 comments
Open

Typo in model.py #8

MrtnStnwk opened this issue Jun 26, 2019 · 4 comments

Comments

@MrtnStnwk
Copy link

There is a little typo in line 191 of model.py:
line 191

self.data_generator = load_data.load_data(
                nr_of_channels=self.batch_size, generator=True, subfolder=image_folder)

should read

self.data_generator = load_data.load_data(
                nr_of_channels=self.channels, batch_size=self.batch_size, generator=True, subfolder=image_folder)
@simontomaskarlsson
Copy link
Owner

Hi @MrtnStnwk,

Thank you for your find, I will update the model right away.

@MrtnStnwk
Copy link
Author

There seems to be another (minor) issue here. If the number of samples is not dividable by the batch_size, it jams after an epoch. (e.g. following: batch size 4, no samples 6287).

Traceback (most recent call last):
  File "model.py", line 924, in <module>
    GAN = CycleGAN()
  File "model.py", line 243, in __init__
    self.train(epochs=self.epochs, batch_size=self.batch_size, save_interval=self.save_interval)
  File "model.py", line 608, in train
    run_training_iteration(loop_index, epoch_iterations)
  File "model.py", line 407, in run_training_iteration
    DB_loss_real = self.D_B.train_on_batch(x=real_images_B, y=ones)
  File "/home/m.steenwijk/miniconda2/lib/python2.7/site-packages/keras/engine/training.py", line 1211, in train_on_batch
    class_weight=class_weight)
  File "/home/m.steenwijk/miniconda2/lib/python2.7/site-packages/keras/engine/training.py", line 804, in _standardize_user_data
    check_array_length_consistency(x, y, sample_weights)
  File "/home/m.steenwijk/miniconda2/lib/python2.7/site-packages/keras/engine/training_utils.py", line 237, in check_array_length_consistency
    'and ' + str(list(set_y)[0]) + ' target samples.')
ValueError: Input arrays should have the same number of samples as target arrays. Found 3 input samples and 4 target samples.

Line numbers may be a little different because I did some modifications.

I suggest the max number of samples should be dividable by the batch size as a fix.

@MrtnStnwk
Copy link
Author

Sorry, I catched another bug (which is only relevant when supervised learning is used).

In load_data it is better to have os.listdir(trainA_path) (and testA, trainB, testB) sorted, because the listdir output is not neccessarily sorted. (output of listdir is dependent on how it is stored in de filesystem).

Solution is to use
trainA_image_names = sorted(os.listdir(trainA_path))

@simontomaskarlsson
Copy link
Owner

Hi @MrtnStnwk,

Seemed to have missed your last post. Great that you are commenting the errors, thank you.
I remember working on the error with number of samples needing to be dividable by the batch size but evidentially it is still a problem in this model. I will add a comment on this for now.

Regarding the sorting error you have found you can create a pull request if you want to, otherwise I will update it myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants