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

Problem when use best_model_pascal_ResFCN.pth #24

Open
ThanhNguyenFG opened this issue Oct 23, 2019 · 4 comments
Open

Problem when use best_model_pascal_ResFCN.pth #24

ThanhNguyenFG opened this issue Oct 23, 2019 · 4 comments

Comments

@ThanhNguyenFG
Copy link

ThanhNguyenFG commented Oct 23, 2019

Hello,
After I ran the command

python main.py -image_path figures/test.png
-model_path checkpoints/best_model_pascal_ResFCN.pth
-model_name ResFCN

I got this error:

"Model: ResFCN - Dataset: pascal - Metric: mRMSE
Traceback (most recent call last):
File "main.py", line 45, in
main()
File "main.py", line 33, in main
applyOnImage.apply(args.image_path, args.model_name, args.model_path)
File "/content/LCFCN/applyOnImage.py", line 34, in apply
imsave(save_path, ut.combine_image_blobs(image_raw, pred_blobs))
File "/usr/local/lib/python3.6/dist-packages/skimage/io/_io.py", line 144, in imsave
return call_plugin('imsave', fname, arr, plugin=plugin, **plugin_args)
File "/usr/local/lib/python3.6/dist-packages/skimage/io/manage_plugins.py", line 210, in call_plugin
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/imageio/core/functions.py", line 253, in imwrite
raise ValueError("Image must be 2D (grayscale, RGB, or RGBA).")
ValueError: Image must be 2D (grayscale, RGB, or RGBA)."

I almost try many images but I can't fix this error.
Did I miss something?
Thank you very much.

@sirtris
Copy link

sirtris commented Oct 24, 2019

I had the same error. I think is because the pred_blobs are of shape [num_classes, img_width, img_height] and the ´image_raw´ is of shape [img_width, img_height, 3] so there is a shape mismatch.
What I did was: pred_blobs_max = np.argmax(pred_blobs, axis=0) and the replace pred_blobs with pred_blobs_max in the imsave line.

However my predictions are very bad I am not sure if I made a mistake here or somewhere else.
Does this solution work for you?

@ThanhNguyenFG
Copy link
Author

Thank you very much,
I fixed and no longer have this error, but the result is exactly what you said (it is very bad) and predict_count is always equal to 0 although blobs has appeared on the image.
.

@tongpinmo
Copy link

@ThanhNguyenFG @sirtris
I have also come accross the problem, according to your method, I fixed my problem, but the result is so strange, my predict_count is normal but the coordinates is on the top of images

@datkungfu
Copy link

@ThanhNguyenFG @sirtris @tongpinmo I have found out the problem with this code. In the file applyOnImage.py you can see the line "pred_counts = int(model.predict(batch, method="counts").ravel()[0])"
But actually, it should become pre_counts= model.predict(batch, method="counts").ravel()
Then, you can add "print(pre_counts)" right after that line and then when we run the file main.py , the result of "print(pre_counts)" would be an array of 20 numbers, they are the number of objects for each class in 20 classes:
"aeroplane":0,
"bicycle":1,
"bird":2,
"boat":3,
"bottle":4,
"bus":5,
"car":6,
"cat":7,
"chair":8,
"cow":9,
"diningtable":10,
"dog":11,
"horse":12,
"motorbike":13,
"person":14,
"pottedplant":15,
"sheep":16,
"sofa":17,
"train":18,
"tvmonitor":19
In the code, author just count the number of object of the first class, "aeroplane".
Next, when we use pred_blob_max as @sirtris , then it would create the density map for the class with highest number of object.

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

4 participants