DeepTrackAI / DeepTrack2

DeepTrack2
MIT License
162 stars 49 forks source link

Lodestar Value Error #110

Closed NuclearHygo closed 2 years ago

NuclearHygo commented 2 years ago

Hi all, I am having some issues with Lodestar. I tried following the tutorial and it does not seem that the learning is working. The error states as follows:

ValueError: Exception encountered when calling layer "sequential_2" (type Sequential).

Input 0 of layer "conv2d_20" is incompatible with the layer: expected axis -1 of input shape to have value 1, but received input with shape (8, 300, 300, 4)

Call arguments received by layer "sequential_2" (type Sequential): • inputs=tf.Tensor(shape=(8, 300, 300, 4), dtype=float32) • training=False • mask=None

I am not sure what this means for the error and would appreciate any help towards solving me that anyone could give me. My image loads and crops fine but after it runs 160 samples it turns out with this error. Thank you in advance!

BenjaminMidtvedt commented 2 years ago

Hi! Seems like you are loading color images, while default LodeSTAR expects grayscale. If there isn't significant color information in the images, I would recommend converting them to grayscale. In other words, LodeSTAR expects crops of shape (W, H, 1) but yours are (W, H, 4).

It is also possible to set the shape parameter of LodeSTAR to (None, None, 4), but I wouldn't recommend this unless there's significant information in the color of the images

NuclearHygo commented 2 years ago

Hi! I tried it and it worked. I changed it with the grayscale from PIL. Thank you very much! There is only an issue where it won't detect the particles afterwards now which I am currently trying to solve

BenjaminMidtvedt commented 2 years ago

It's hard to diagnose what could be wrong. There are a few things I would look at. First, try decreasing cutoff until particles are detected to see if it is working at all. Second, I would look at the loss during training. Does it decrease? A loss under 0.5 is usually good enough. If it does not decrease, I would look at the crops you feed it. Make sure that there is at most one object in each crop (if you use more than one). Also, if the crops are large (> 150 px), consider downsampling with for example dt.AveragePooling((4, 4, 1))(crop) or any other library you prefer. Feel free to change the downsampling parameter as you like. Keep in mind that you will need to downsample the data you evaluate on the same amount.

NuclearHygo commented 2 years ago

Thank you very much for your answer! I tried rearranging the values and got something somewhat decent. I will try your recommendation on downsampling to see the difference. Thank you!