juglab / n2v

This is the implementation of Noise2Void training.
Other
394 stars 108 forks source link

Issue when training #120

Closed farazahmeds closed 2 years ago

farazahmeds commented 2 years ago

Hello,

I was hoping if someone can help, I get the following error when I train on a grayscale image:


Epoch 1/25
Traceback (most recent call last):
  File "/home/faraz/PycharmProjects/N2VPETCT/my_data/petimage.py", line 61, in <module>
    history = model.train(X, X_val)
  File "/home/faraz/anaconda3/envs/n2vx/lib/python3.6/site-packages/n2v/models/n2v_standard.py", line 240, in train
    callbacks=self.callbacks, verbose=1)
  File "/home/faraz/anaconda3/envs/n2vx/lib/python3.6/site-packages/keras/legacy/interfaces.py", line 91, in wrapper
    return func(*args, **kwargs)
  File "/home/faraz/anaconda3/envs/n2vx/lib/python3.6/site-packages/keras/engine/training.py", line 1658, in fit_generator
    initial_epoch=initial_epoch)
  File "/home/faraz/anaconda3/envs/n2vx/lib/python3.6/site-packages/keras/engine/training_generator.py", line 181, in fit_generator
    generator_output = next(output_generator)
  File "/home/faraz/anaconda3/envs/n2vx/lib/python3.6/site-packages/keras/utils/data_utils.py", line 616, in get
    six.reraise(*sys.exc_info())
  File "/home/faraz/anaconda3/envs/n2vx/lib/python3.6/site-packages/six.py", line 719, in reraise
    raise value
  File "/home/faraz/anaconda3/envs/n2vx/lib/python3.6/site-packages/keras/utils/data_utils.py", line 603, in get
    inputs = future.get(timeout=30)
  File "/home/faraz/anaconda3/envs/n2vx/lib/python3.6/multiprocessing/pool.py", line 644, in get
    raise self._value
  File "/home/faraz/anaconda3/envs/n2vx/lib/python3.6/multiprocessing/pool.py", line 119, in worker
    result = (True, func(*args, **kwds))
  File "/home/faraz/anaconda3/envs/n2vx/lib/python3.6/site-packages/keras/utils/data_utils.py", line 406, in get_index
    return _SHARED_SEQUENCES[uid][i]
  File "/home/faraz/anaconda3/envs/n2vx/lib/python3.6/site-packages/n2v/internals/N2V_DataWrapper.py", line 71, in __getitem__
    self.patch_sampler(self.X, self.X_Batches, indices=idx, range=self.range, shape=self.shape)
  File "/home/faraz/anaconda3/envs/n2vx/lib/python3.6/site-packages/n2v/internals/N2V_DataWrapper.py", line 116, in __subpatch_sampling2D__
    y_start = np.random.randint(0, range[0] + 1)
  File "mtrand.pyx", line 746, in numpy.random.mtrand.RandomState.randint
  File "_bounded_integers.pyx", line 1254, in numpy.random._bounded_integers._rand_int64
ValueError: low >= high

Process finished with exit code 1

Also when I pass the grayscale image to load_imgs_from_directory object I get the following theshape (1, 4, 199, 199, 1) why does it add extra dimension?

Code:


datagen = N2V_DataGenerator()

imgs = datagen.load_imgs_from_directory(directory="data/", filter='*.png', dims='YXZ')

patch_shape=(16,16)
patches = datagen.generate_patches_from_list(imgs[0], shape=patch_shape)

X = patches[:1000]
X_val = patches[1000:]

config = N2VConfig(X, unet_kern_size=3,
                   unet_n_first=64, unet_n_depth=3,train_epochs=25, train_loss='mse',
                   batch_norm=True, train_batch_size=128, n2v_perc_pix=0.198, n2v_patch_shape=(64, 64),
                   n2v_manipulator='uniform_withCP', n2v_neighborhood_radius=5, single_net_per_channel=False)

model_name = 'pet_model'
basedir = 'models'
model = N2V(config, model_name, basedir=basedir)

history = model.train(X, X_val)
farazahmeds commented 2 years ago

I made a mistake when passing the window size for n2v_patch_shape