fmi-basel / buehler-colonyclassification

Pipeline for automated yeast colony classification using neural networks
GNU General Public License v3.0
2 stars 1 forks source link

Unknown error in segmentation #1

Open RiescoR opened 4 years ago

RiescoR commented 4 years ago

I´ve tried to apply the pipeline to a jpeg photo in a folder called colony with the order python integrated_segmentation_classification.py --destdir D:\Datos\Desktop\buehler-colonyclassification-master\colony

and the output is Traceback (most recent call last): File "integrated_segmentation_classification.py", line 342, in main() File "integrated_segmentation_classification.py", line 34, in main predict_seg(MODELPATH, IOPATH) File "integrated_segmentation_classification.py", line 192, in predict_seg cropped[i] = cropimread(test_x[i]) ValueError: could not broadcast input array from shape (550,0,3) into shape (543,543,3)

Don´t know if it is the dependencies, I had to install fastai 0.7 environment (quite challenging as it is depreciated). I also had to install scikit-image (conda install -c anaconda scikit-image, as a problem arise with this module). I´,m working on windows, but I get the same error in Linux. Can be due to a format error of the photograph? Is there an example input anywhere? Could it be due to the dependencies?

RiescoR commented 4 years ago

I finally found a jpg image used in the train folder for segmentation, and id does the trick, It segments the image. However, I can´t get the csv table, I think I still have a problem with dependencies (fastai) D:\Datos\Desktop\buehler-colonyclassification-master>python integrated_segmentation_classification.py --destdir D:\Datos\Desktop\buehler-colonyclassification-master\colonias C:\Users\Usuario\Anaconda3\envs\fastai\lib\site-packages\skimage\measure_regionprops.py:250: UserWarning: regionprops and image moments (including moments, normalized moments, central moments, and inertia tensor) of 2D images will change from xy coordinates to rc coordinates in version 0.16. See https://scikit-image.org/docs/0.14.x/release_notes_and_installation.html#deprecations for details on how to avoid this message. warn(XY_TO_RC_DEPRECATION_MESSAGE) C:\Users\Usuario\Anaconda3\envs\fastai\lib\site-packages\skimage\measure_regionprops.py:260: UserWarning: regionprops and image moments (including moments, normalized moments, central moments, and inertia tensor) of 2D images will change from xy coordinates to rc coordinates in version 0.16. See https://scikit-image.org/docs/0.14.x/release_notes_and_installation.html#deprecations for details on how to avoid this message. warn(XY_TO_RC_DEPRECATION_MESSAGE) ....\colonias\cropped\20180418_mwm_d10000021 Traceback (most recent call last): File "integrated_segmentation_classification.py", line 342, in main() File "integrated_segmentation_classification.py", line 35, in main predict_freqs(MODELPATH, IOPATH) File "integrated_segmentation_classification.py", line 281, in predict_freqs full_df.to_csv(IOPATH/summary_filename, na_rep="0") File "C:\Users\Usuario\Anaconda3\envs\fastai\lib\site-packages\pandas\core\generic.py", line 3228, in to_csv formatter.save() File "C:\Users\Usuario\Anaconda3\envs\fastai\lib\site-packages\pandas\io\formats\csvs.py", line 183, in save compression=self.compression, File "C:\Users\Usuario\Anaconda3\envs\fastai\lib\site-packages\pandas\io\common.py", line 399, in _get_handle f = open(path_or_buf, mode, encoding=encoding, newline="") OSError: [Errno 22] Invalid argument: 'D:\Datos\Desktop\buehler-colonyclassification-master\colonias\2020-01-16_12:36:24_summary.csv'

sarahhcarl commented 4 years ago

Hi @RiescoR ,

Thanks for trying out the pipeline. Are you still having problems with the segmentation? If so, could you tell me which version of scikit-image you have installed, and also the dimensions of your .jpeg file?

The second error sounds like it's a problem with the filepath. Do you get the same error if you try to run it on a linux machine? Were you able to write anything in the output directory on Windows (e.g. the segmented images)?

Best, Sarah

RiescoR commented 4 years ago

Hello, sorry for the late reply, and thank you for the answer I successfully installed in linux. I used the image contained in ./buehler-colonyclassification/pretrained/segmentation/train as a positive test and it worked (it produced the csv and the colony segmentation folder). However, when I try to run any of my photos I always get variants of the same error:

Traceback (most recent call last): File "integrated_segmentation_classification.py", line 342, in main() File "integrated_segmentation_classification.py", line 34, in main predict_seg(MODELPATH, IOPATH) File "integrated_segmentation_classification.py", line 192, in predict_seg cropped[i] = cropimread(test_x[i]) ValueError: could not broadcast input array from shape (5184,0,3) into shape (5144,5144,3)

The differences were in the shape numbers (shape (X, Y, Z)), depending on the input jpg image. I tried with several dimensions 2000X2015, 3473X3500 and 5144X5184 at 72ppp and 300ppp, but none of them worked. The version of the scitkit-image is 0.16.2

sarahhcarl commented 4 years ago

Hi @RiescoR ,

I think the problem was caused by a silly bug in my function to center-crop images, which should now be fixed. Could you try downloading the updated version of the segmentation script and running it again?

Cheers, Sarah

RiescoR commented 4 years ago

Hello Sarah, thanks for the reply I redownloaded the whole master repository, and I tested it on several images with different resolutions as the last time. I have a variation of the same error, however, this time I get the first shape as (X, X, Y) (the two starting factors as the same). I send you the error I get

Traceback (most recent call last): File "integrated_segmentation_classification.py", line 349, in main() File "integrated_segmentation_classification.py", line 35, in main predict_seg(MODELPATH, IOPATH) File "integrated_segmentation_classification.py", line 199, in predict_seg cropped[i] = cropimread(test_x[i]) ValueError: could not broadcast input array from shape (3500,3447,3) into shape (3473,3473,3)

I guessed that one of the initial steps is resize the jpg into a perfect square image, and that the pipeline could be failing there, so I converted the jpg into a perfect square image with an image editor program (GIMP). However, with this input I reverted to the same error of the first message (please note the 0 in the first shape parameter)

Traceback (most recent call last): File "integrated_segmentation_classification.py", line 349, in main() File "integrated_segmentation_classification.py", line 35, in main predict_seg(MODELPATH, IOPATH) File "integrated_segmentation_classification.py", line 199, in predict_seg cropped[i] = cropimread(test_x[i]) ValueError: could not broadcast input array from shape (3473,0,3) into shape (3473,3473,3)

Again, thank you very much for your time and effort >_<

sarahhcarl commented 4 years ago

Could you try again now? I found another bug that I've fixed, and I've also changed the code to handle perfectly square images (I was assuming before that they would be rectangular). It would be great if you could test both cases.

One note however, the current pipeline will not work if you try to run it on images of different sizes at the same time, because it's getting the expected dimensions from the first image it encounters (for segmentation). That's something I could potentially improve, if you have many images of all different sizes.

Fingers crossed it works now, at least on images of the same dimensions!

RiescoR commented 4 years ago

Hello Sarah, With the perfectly square pictures it works! For all the images I created, in the 3 sizes I tried (2000X2000; 3473X3473 and 5144X5144). Great work! However, when resizing was necessary, the pipeline behavior was rather inconsistent. I tried 6 images, 2 with 2000x2015, 2 with 3473x3500 and 2 with 5144x5184. It only worked with 2 of them, one with 5144x5184 and other with 3473x3500. The other four failed with the following errors:

Traceback (most recent call last): File "integrated_segmentation_classification.py", line 352, in main() File "integrated_segmentation_classification.py", line 35, in main predict_seg(MODELPATH, IOPATH) File "integrated_segmentation_classification.py", line 202, in predict_seg cropped[i] = cropimread(test_x[i]) ValueError: could not broadcast input array from shape (2001,2000,3) into shape (2000,2000,3)

Traceback (most recent call last): File "integrated_segmentation_classification.py", line 352, in main() File "integrated_segmentation_classification.py", line 35, in main predict_seg(MODELPATH, IOPATH) File "integrated_segmentation_classification.py", line 202, in predict_seg cropped[i] = cropimread(test_x[i]) ValueError: could not broadcast input array from shape (3474,3473,3) into shape (3473,3473,3)

Traceback (most recent call last): File "integrated_segmentation_classification.py", line 352, in main() File "integrated_segmentation_classification.py", line 35, in main predict_seg(MODELPATH, IOPATH) File "integrated_segmentation_classification.py", line 202, in predict_seg cropped[i] = cropimread(test_x[i]) ValueError: could not broadcast input array from shape (5145,5144,3) into shape (5144,5144,3)

As you can see, for some reason in the first shape it is always (X+1, X, 3), maybe it is getting the wrong sizes from the input photos? However, I can not imagine why the pipeline works for two of the photos, they do not even have the same size. I also tried with the two photos that worked at the same time, just to see what happens, and as you warned, it also gave a resizing error problem. I think that could be a good improvement for the future: if a picture is different in even 1 pixel, it won´t work >_<. And if you had 30 images it can be quite challenging to find the misshaped one (if you use a photo editor small resizes are quite common). But it is just an opinion, with a warning in the readme the user will be aware and will take care of the input 😊. Thank you very much for all the work!!

sarahhcarl commented 4 years ago

Hi @RiescoR ,

Sorry it took me a while to get back to you - I didn't have much time to work on this in the last week.

I've implemented what should be a fix to the off-by-one pixel problem in the original script. I'm a little concerned about the fact that it was working for one file and failing for another of the same dimensions (did I understand that right?). But, let's see if it works now.

At the same time, I did some re-factoring, and I created a new script called "integrated_segmentation_classification_v2.py" which should be able to handle images of multiple sizes in the same run. So far it has worked for me, but I've only tested it on two different sized images.

I hope that's helpful! Let me know if v2 works for you, and if so then I will change it to be the standard method.

Cheers, Sarah