qurator-spk / sbb_binarization

Document Image Binarization
Apache License 2.0
67 stars 14 forks source link

Handle input errors in exceptions #30

Closed hiyashi-CianDuo closed 1 year ago

hiyashi-CianDuo commented 3 years ago

Hello I trying to use image input "sbb_binarize --patches -m ./models/model_bin_sbb_ens.h5 179681.png img.png"

I get the following error " File "/home/lin/anaconda3/bin/sbb_binarize", line 8, in sys.exit(main()) File "/home/lin/anaconda3/lib/python3.5/site-packages/click/core.py", line 829, in call return self.main(args, kwargs) File "/home/lin/anaconda3/lib/python3.5/site-packages/click/core.py", line 782, in main rv = self.invoke(ctx) File "/home/lin/anaconda3/lib/python3.5/site-packages/click/core.py", line 1066, in invoke return ctx.invoke(self.callback, ctx.params) File "/home/lin/anaconda3/lib/python3.5/site-packages/click/core.py", line 610, in invoke return callback(args, **kwargs) File "/home/lin/anaconda3/lib/python3.5/site-packages/sbb_binarize/cli.py", line 16, in main SbbBinarizer(model_dir).run(image_path=input_image, use_patches=patches, save=output_image) File "/home/lin/anaconda3/lib/python3.5/site-packages/sbb_binarize/sbb_binarize.py", line 265, in run img_last[:, :][img_last[:, :] > 0] = 255 TypeError: 'int' object is not subscriptable"

vahidrezanezhad commented 3 years ago

Dear Hiyashi,

Can you please share your input image?

hiyashi-CianDuo commented 3 years ago

Hello vahidrezanezhad, Thanks for your reply

This is the input image: 179681

and I use this command and get the this image inforation $identify 179681.jpg 179681.jpg JPEG 392x294 392x294+0+0 8-bit sRGB 52.6KB 0.000u 0:00.000

vahidrezanezhad commented 3 years ago

Dear Hiyashi,

I have just checked this image and sbb_biarize goes through smoothly. Please update and double-check your command. I will put the binarized image here.

vahidrezanezhad commented 3 years ago

hiyashi

hiyashi-CianDuo commented 3 years ago

Hello vahidrezanezhad, Thanks for your reply I want to ask you Is the format of the command I entered correctly? "sbb_binarize --patches -m ./models/model_bin_sbb_ens.h5 179681.jpg img.jpg"

vahidrezanezhad commented 3 years ago

oh I have just spotted the problem. You don't need to specify the model name. Just the directory where the model is.

It should be like this "sbb_binarize --patches -m ./models 179681.jpg img.jpg"

vahidrezanezhad commented 3 years ago

If you have multiple models in the directory, sbb_binarize would use all of them. Be careful that for the latest version you need only this model "model_bin_sbb_ens.h5"

hiyashi-CianDuo commented 3 years ago

Hello vahidrezanezhad, thanks for your help I know the cause of the problem and it has been resolved The cause of the problem is the path setting of the model The model must be placed in the sbb_binarization folder instead of the models folder thank you very much

hiyashi-CianDuo commented 3 years ago

Hello vahidrezanezhad, If I want to use usb_camera or a lot of pictures, how can I use it?

vahidrezanezhad commented 3 years ago

Does it mean you wanna flow images into sbb_binarize from a list of images? sth like this?

hiyashi-CianDuo commented 3 years ago

Yes it should be the same way

vahidrezanezhad commented 3 years ago

Dear Hiyashami,

you can use this script to flow all your files

https://github.com/vahidrezanezhad/sbb_binarize_flow_from_directory

hiyashi-CianDuo commented 3 years ago

Hello vahidrezanezhad, thanks for your help Sorry to reply to you late, The solution you provided works normally I have some questions to ask you, It takes 10-19 seconds to run an image, Is this the time it would take for the original design of the program? Is there no way to run it in real-time?

vahidrezanezhad commented 3 years ago

Are you running on GPU or CPU? by the way our tools binarize in small patches and then all patches merged as the final image. So you can imagine that if you have a bigger image, namely more patches is needed, then sbb_binarize needs more time to do the job.

On Wed, May 26, 2021 at 11:25 PM hiyashi-CianDuo @.***> wrote:

Hello vahidrezanezhad, thanks for your help Sorry to reply to you late, The solution you provided works normally I have some questions to ask you, It takes 10-19 seconds to run an image, Is this the time it would take for the original design of the program? Is there no way to run it in real-time?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/qurator-spk/sbb_binarization/issues/30#issuecomment-849289426, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGIWJ5SKII6BL7N7RII5N7TTPW3RFANCNFSM45NKMGWQ .

bertsky commented 2 years ago

Note: this also happens in the OCR-D interface, if you use the wrong model name. I think there should be a proper exception during init for this.

cneud commented 2 years ago

I think there should be a proper exception during init for this

I agree!

cneud commented 2 years ago

Thanks @vahidrezanezhad.

@kba I will leave this issue open until we have added a similar construct to ocrd_cli.py

Heavenbest commented 1 year ago

https://github.com/qurator-spk/sbb_binarization/issues/30#issue-899709182

I got the same question with you,the model cannot find correctly,
as follow,you said that: ""The cause of the problem is the path setting of the model The model must be placed in the sbb_binarization folder instead of the models folder""

please tell me which folder ? maybe I can't find sbb_binarization folder, I have tried many times.

@hiyashi-CianDuo

vahidrezanezhad commented 1 year ago

#30 (comment)

I got the same question with you,the model cannot find correctly, as follow,you said that: ""The cause of the problem is the path setting of the model The model must be placed in the sbb_binarization folder instead of the models folder""

please tell me which folder ? maybe I can't find sbb_binarization folder, I have tried many times.

@hiyashi-CianDuo

could you please share your command and the error?

Heavenbest commented 1 year ago

@vahidrezanezhad

(base)ps@amax:~/sbb_binarization-master$ ls build LICENSE models requirements.txt CHANGELOG.md Makefile ocrd-tool.json sbb_binarization.egg-info dist make.sh README.md sbb_binarize IMG_20220114_134650.jpg model_bin_sbb_ens.h5 repo setup.py (base)ps@amax:~/sbb_binarization-master$ sbb_binarize --patches -m ./models/ ./IMG_20220114_134650.jpg ./img.jpg Traceback (most recent call last): File "/data/ps/miniconda3/bin/sbb_binarize", line 8, in sys.exit(main()) File "/data/ps/miniconda3/lib/python3.9/site-packages/click/core.py", line 1130, in call return self.main(args, kwargs) File "/data/ps/miniconda3/lib/python3.9/site-packages/click/core.py", line 1055, in main rv = self.invoke(ctx) File "/data/ps/miniconda3/lib/python3.9/site-packages/click/core.py", line 1404, in invoke return ctx.invoke(self.callback, ctx.params) File "/data/ps/miniconda3/lib/python3.9/site-packages/click/core.py", line 760, in invoke return __callback(args, **kwargs) File "/data/ps/.local/lib/python3.9/site-packages/sbb_binarization-0.0.9-py3.9.egg/sbb_binarize/cli.py", line 15, in main File "/data/ps/.local/lib/python3.9/site-packages/sbb_binarization-0.0.9-py3.9.egg/sbb_binarize/sbb_binarize.py", line 40, in init File "/data/ps/.local/lib/python3.9/site-packages/sbb_binarization-0.0.9-py3.9.egg/sbb_binarize/sbb_binarize.py", line 55, in load_model File "/data/ps/miniconda3/lib/python3.9/site-packages/keras/utils/traceback_utils.py", line 67, in error_handler raise e.with_traceback(filtered_tb) from None File "/data/ps/miniconda3/lib/python3.9/site-packages/keras/saving/save.py", line 206, in load_model raise IOError(f'No file or directory found at {filepath_str}') OSError: No file or directory found at ./models/./models/model_bin_sbb_ens.h5

the command and the error as blow.

dajor commented 1 year ago

Looks like I have the same issue.

The model is model/model/model_bin_sbb_ens.h5

run on Mac no GPU

sbb_binarize --patches -m ./model/ 1.jpg 2.jpg

Traceback (most recent call last): File "/Users/daniel/dev/sbb_binarization/venv/bin/sbb_binarize", line 33, in sys.exit(load_entry_point('sbb-binarization', 'console_scripts', 'sbb_binarize')()) File "/Users/daniel/dev/sbb_binarization/venv/lib/python3.8/site-packages/click/core.py", line 1130, in call return self.main(args, kwargs) File "/Users/daniel/dev/sbb_binarization/venv/lib/python3.8/site-packages/click/core.py", line 1055, in main rv = self.invoke(ctx) File "/Users/daniel/dev/sbb_binarization/venv/lib/python3.8/site-packages/click/core.py", line 1404, in invoke return ctx.invoke(self.callback, ctx.params) File "/Users/daniel/dev/sbb_binarization/venv/lib/python3.8/site-packages/click/core.py", line 760, in invoke return __callback(args, **kwargs) File "/Users/daniel/dev/sbb_binarization/sbb_binarize/cli.py", line 15, in main SbbBinarizer(model_dir).run(image_path=input_image, use_patches=patches, save=output_image) File "/Users/daniel/dev/sbb_binarization/sbb_binarize/sbb_binarize.py", line 270, in run img_last[:, :][img_last[:, :] > 0] = 255 TypeError: 'int' object is not subscriptable