juglab / n2v

This is the implementation of Noise2Void training.
Other
387 stars 107 forks source link

Structured N2V; 'float' object has no attribute 'item' in training #95

Closed citypalmtree closed 4 years ago

citypalmtree commented 4 years ago

Hello.

I am having an issue when I try to use Structured N2V. Here is my notebook for your reference.

https://github.com/citypalmtree/publicc/blob/master/struct_n2v_colab.ipynb

I made sure that my image resembles the image used in the example, flower.tif. Instead of that 'flower.tif' has 100 images stacked, I only stacked 4 images. Both are 16-bit images.

In training, I keep getting an error of 'float' object has no attribute 'item' Following the code in the libraries, I am assuming it's related to Tensorboard, but I am not sure why it raises the error. Here is the ticket issued in Keras that I found and it looks like it had a same issue. https://github.com/keras-team/keras/pull/10673

I wanted to test the code with 'flower.tif,' but it kept crashing in Google Colab. So I couldn't really check whether the issue is because of my data set.

Please let me know if you need more information. Thank you in advance!

tibuch commented 4 years ago

Pinging @colemanbroad :slightly_smiling_face:

citypalmtree commented 4 years ago

Thank you @tibuch

Another update to this issue is that structured N2V training WORKS if I restart kernels and try again several times (or once on some occasion).

I thought the issue was inherent to Google Colab, but it also persisted when I tried with my computer's GPU in Anaconda>Jupyter Notebook.

I have a side question if you don't mind. Whenever I train the images, my validation loss is always higher than training loss, and the output images are not as good as a regular N2V. I am using a set of 14 images that were taken on the same day and the same environment. The difference between your example and my data set was the number of patches for training and validation created: Generated patches: (1344, 96, 96, 1) Generated patches: (2016, 96, 96, 1)

Your example had Generated patches: (640, 96, 96, 1) Generated patches: (160, 96, 96, 1)

Would that be the cause of higher val_loss? Would you know what I can do to create fewer validation patches than training patches? The size of my image is 2048X2048 And the pixel range is from 0 to 1.

Do you also recommend normalizing images before predicting? I read it that structured N2V normalizes the training images, but I wasn't sure if it also normalizes input images in prediction automatically.

Any advice would be greatly appreciated! Thank you.

colemanbroad commented 4 years ago

Hi @citypalmtree, thanks for checking out StructN2V / N2V!

Does the 'float' object has no attribute 'item' error persist? It does look like similar, older keras/tensorboard interop issues (they even have the same variable names!) But in theory this was fixed a while back in keras 2.2.2.

What happens if you bump your keras from 2.2.4 -> 2.2.5? Further upgrades might now be possible, but we'd have to ask @tibuch.


the output images are not as good as a regular N2V Do you have structured noise (like visible vertical / horizontal stripes or stretching) in your data? For most datasets we would expect N2V to be the first choice!

Would that be the cause of higher val_loss? Would you know what I can do to create fewer validation patches than training patches?

How large is the difference? Does it persist when you exchange the train/vali data? Since your original dataset only has 4 images (size 4x2048x2048x1) you might want to shuffle the dataset after splitting it up into patches. You should be able to just shuffle the data around like so:

patch_shape = (96,96)
X = datagen.generate_patches_from_list(imgs[0], shape=patch_shape)
np.random.shuffle(X)
X_val = X[1200:] # adjust this number to control train/vali split
X = X[:1200]

Do you also recommend normalizing images before predicting? The mean and stddev are set internally to 0,1 so you don't need to normalize them.

cheers! Coleman

citypalmtree commented 4 years ago

Hi @colemanbroad!

Thank you for your response. The issue with 'float' object has no attribute 'item' doesn't persist. It appears in the first run, and the kernel automatically restarts. In the second run, the issue doesn't come up. Also, if I choose a smaller amount of images to train, the issue never appears.

Thank you very much!