text-detection-ctpn icon indicating copy to clipboard operation
text-detection-ctpn copied to clipboard

Run demo.py on windows with cpu successfully!

Open ZhuMingmin9123 opened this issue 6 years ago • 36 comments

thanks to the author and #43 zhao181

my environment is: windows10 , python3.6 , tensorflow1.3 , vs2015(ps:vs2013 not support python3.6 when compile)

step 1:make some change change "np.int_t " to "np.intp_t" in line 25 of the file lib\utils\cython_nms.pyx otherwise appear " ValueError: Buffer dtype mismatch, expected 'int_t' but got 'long long' " in step 6.

step 2:updata c file execute:cd your_dir\text-detection-ctpn-master\lib\utils execute:cython bbox.pyx execute:cython cython_nms.pyx

step 3:builf setup file as setup_new.py import numpy as np from distutils.core import setup from Cython.Build import cythonize from distutils.extension import Extension numpy_include = np.get_include() setup(ext_modules=cythonize("bbox.pyx"),include_dirs=[numpy_include]) setup(ext_modules=cythonize("cython_nms.pyx"),include_dirs=[numpy_include])

step 4:build .pyd file execute:python setup_new.py install copy bbox.cp36-win_amd64.pyd and cython_nms.cp36-win_amd64.pyd to your_dir\text-detection-ctpn-master\lib\utils

step 5:make some change (1) Set "USE_GPU_NMS " in the file \ctpn\text.yml as "False" (2) Set the "_C.USE_GPU_NMS" in the file \lib\fast_rcnn\config.py as "False"; (3) Comment out the line "from lib.utils.gpu_nms import gpu_nms" in the file \lib\fast_rcnn\nms_wrapper.py; (4) Comment out the line "from . import gpu_nms" in the file \lib\utils_init.py; (5) change "base_name = image_name.split('/')[-1]" to "base_name = image_name.split('\')[-1]" in line 24 of the file ctpn\demo.py

step 6:run demo execute:cd your_dir\text-detection-ctpn-master execute:python ./ctpn/demo.py

ZhuMingmin9123 avatar Dec 28 '17 16:12 ZhuMingmin9123

@ZhuMingmin9123 Thanks for the sharing.

eragonruan avatar Dec 29 '17 09:12 eragonruan

Thank you!!!

xmq1996 avatar Jan 10 '18 11:01 xmq1996

thank you! But the change in the step5 should be like this: " image_name.split('/')[-1]" to "image_name.split('\')[-1]" in line 24.

qinxianyuzi avatar Jan 25 '18 05:01 qinxianyuzi

thank you very much, that's ok

zhLawliet avatar Jan 27 '18 07:01 zhLawliet

@ZhuMingmin9123 hi, if i want to run demo.py on windows with GPU, how to do? thanks running install running build running build_ext Traceback (most recent call last): File "setup.py", line 106, in cmdclass={'build_ext': custom_build_ext}, File "E:\Anaconda3\lib\distutils\core.py", line 148, in setup dist.run_commands() File "E:\Anaconda3\lib\distutils\dist.py", line 955, in run_commands self.run_command(cmd) File "E:\Anaconda3\lib\distutils\dist.py", line 974, in run_command cmd_obj.run() File "E:\Anaconda3\lib\distutils\command\install.py", line 539, in run self.run_command('build') File "E:\Anaconda3\lib\distutils\cmd.py", line 313, in run_command self.distribution.run_command(command) File "E:\Anaconda3\lib\distutils\dist.py", line 974, in run_command cmd_obj.run() File "E:\Anaconda3\lib\distutils\command\build.py", line 135, in run self.run_command(cmd_name) File "E:\Anaconda3\lib\distutils\cmd.py", line 313, in run_command self.distribution.run_command(command) File "E:\Anaconda3\lib\distutils\dist.py", line 974, in run_command cmd_obj.run() File "E:\Anaconda3\lib\site-packages\Cython\Distutils\build_ext.py", line 164, in run _build_ext.build_ext.run(self) File "E:\Anaconda3\lib\distutils\command\build_ext.py", line 338, in run self.build_extensions() File "setup.py", line 72, in build_extensions customize_compiler_for_nvcc(self.compiler) File "setup.py", line 49, in customize_compiler_for_nvcc default_compiler_so = self.compiler_so AttributeError: 'MSVCCompiler' object has no attribute 'compiler_so'

zhLawliet avatar Jan 29 '18 07:01 zhLawliet

In addition, change os.makedirs("data/results/") to os.makedirs("data/results") in line 71 of the file demo.py, otherwise the results dir can't be created.

yotoamoy avatar Feb 06 '18 06:02 yotoamoy

Thank you very much for your code which works perfectly well on my Windows with CPU.

Actually I found that after the setting up with CPU setup.py, I turned to another conda environment with tensorflow-gpu installed and it (running demo.py) also works perfectly( I failed in the setup.py with GPU configration in windows). The running time is really reduced(for CPU Intel i7-6700hq, ~6.1 second/picture and for GPU Nvidia GTX 1060, ~2.9 second). Is there anything different with directly setting up with GPU configration?

jzhongaa avatar Feb 26 '18 09:02 jzhongaa

@zhLawliet Have you solved your problem? I have the same problem with you. AttributeError: 'MSVCCompiler' object has no attribute 'compiler_so'

chenzhongzheng avatar Feb 28 '18 10:02 chenzhongzheng

@ZhuMingmin9123 I have tried your method.But when I run the demo.py in PyCharm at step6,it doesn't work.The error is:Error running 'demo': Cannot run program "C:\Users\82703\anaconda2\envs\py35\bin\python" (in directory "D:\python_project\text-detection-ctpn-master"): CreateProcess error=2, 系统找不到指定的文件。It's so strange,because I do not have the path of "C:\Users\82703\anaconda2\envs\py35\bin\python" in my computer and I did install the requirement except tensorflow_gpu.Could you give me some help?Thank you very much

ExplorerLu avatar Mar 09 '18 02:03 ExplorerLu

thank you very much!

hailang518 avatar Mar 13 '18 08:03 hailang518

After I change code of ctpn\demo.py in line 24 base_name = image_name.split('/')[-1] to base_name = image_name.split('\')[-1]

There are some error appeared. And error meesage like this:

File "demo.py", line 24 base_name = image_name.split('\')[-1] SyntaxError: EOL while scanning string literal

Is anybody can help me, or teach me how to fix the error? Thank a lot.

FarrWu avatar Mar 19 '18 06:03 FarrWu

After I change code of ctpn\demo.py in line 24 base_name = image_name.split('/')[-1] to base_name = image_name.split('\')[-1] There are some error appeared. And error meesage like this: ......


I found the problem. The reason is dir path in windows os use "\" to separate folder or file name. But in python or some other codes, it's should be used like '\\'.

So... I change ctpn\demo.py in line 24 ...

base_name = image_name.split('/')[-1] to base_name = image_name.split('\\')[-1]

It's work!

FarrWu avatar Mar 19 '18 07:03 FarrWu

When I run the demo, there is a problem about this:

Demo for E:\模型\text-detection\text-detection-ctpn\data\demo\001.jpg Traceback (most recent call last): File "./ctpn/demo.py", line 100, in ctpn(sess, net, im_name) File "./ctpn/demo.py", line 54, in ctpn img, scale = resize_im(img, scale=TextLineCfg.SCALE, max_scale=TextLineCfg.M AX_SCALE) File "./ctpn/demo.py", line 17, in resize_im f=float(scale)/min(im.shape[0], im.shape[1]) AttributeError: 'NoneType' object has no attribute 'shape'

Is anybody can help me, or teach me how to fix the error? Thank a lot.

hongdajun avatar Mar 27 '18 07:03 hongdajun

@hongdajun The image was not read in successfully. hence the shape of the image is None

eragonruan avatar Apr 01 '18 03:04 eragonruan

@zhLawliet I have the same problems with you.@ZhuMingmin9123 I really want to know how to run demo.py on Windows with GPU.Please let me know when making it.Thanks a lot

wileewang avatar Apr 13 '18 07:04 wileewang

i am getting lib.networks no module found error_cpu

balajiwix avatar Apr 19 '18 17:04 balajiwix

you should edit some code and modification plugin version {(-_-)}

                                       ---funnyZpC---

在 2018年4月20日,01:53,balajiwix [email protected] 写道:

i am getting lib.networks no module found

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

funnyzpc avatar Apr 21 '18 02:04 funnyzpc

@eragonruan raise 'Check your pretrained {:s}'.format(ckpt.model_checkpoint_path) AttributeError: 'NoneType' object has no attribute 'model_checkpoint_path'

goldwater668 avatar May 18 '18 06:05 goldwater668

@eragonruan raise 'Check your pretrained {:s}'.format(ckpt.model_checkpoint_path) AttributeError: 'NoneType' object has no attribute 'model_checkpoint_path'

goldwater668 avatar May 18 '18 06:05 goldwater668

When I run the demo, there is a problem about this:

File "cython_nms.pyx", line 28, in lib.utils.cython_nms.nms

ValueError: Buffer dtype mismatch, expected 'intp_t' but got 'long'

     [[Node: rois/PyFunc = PyFunc[Tin=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_STRING, DT_INT32, DT_INT32], Tout=[DT_FLOAT, DT_FLOAT], token="pyfunc_0", _device="/job:localhost/replica:0/task:0/device:CPU:0"](Reshape_2, rpn_bbox_pred/Reshape_1, _arg_Placeholder_1_0_1, rois/PyFunc/input_3, rois/PyFunc/input_4, rois/PyFunc/input_4)]]

cks1999 avatar May 25 '18 01:05 cks1999

@hongdajun the path of image demo should not have any Chinese character

howsome avatar Jun 04 '18 03:06 howsome

@cks1999 replace int_t to intp_t. if this does not work. try update your cython version

eragonruan avatar Jun 07 '18 07:06 eragonruan

@ZhuMingmin9123 When I run step 4, I have this error: _sluvz7s 1wducwu or 13d I don't know where is the problem.

hzyxjtu avatar Jun 18 '18 09:06 hzyxjtu

i am getting lib.networks no module found error_cpu

i am getting lib.networks no module found error_cpu

Have you solved this problem?I have the same one.Ask for help,thank you!

wangdaqian avatar Sep 13 '18 09:09 wangdaqian

Has anybody created a fork with cpu enabled modifications?

simonfranz avatar Sep 13 '18 19:09 simonfranz

Hi: You can see my blog:https://www.cnblogs.com/funnyzpc/p/8908906.html

Simon [email protected] 于2018年9月14日周五 上午3:58写道:

Has anybody created a fork with cpu enabled modifications?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/eragonruan/text-detection-ctpn/issues/73#issuecomment-421133259, or mute the thread https://github.com/notifications/unsubscribe-auth/AYsR-Mv92olc6C86pMbXa1-rePE52wbaks5uarjQgaJpZM4ROemo .

--

           For:

           funnyZpC

funnyzpc avatar Sep 15 '18 01:09 funnyzpc

@ZhuMingmin9123 step4: build .pyd file ? How to do this step?Can you help me explain in detail? PS:When I execute:python setup_new.py install,there is an error here: building 'lib.utils.bbox' extension error: Unable to find vcvarsall.bat

scaler2017 avatar Sep 18 '18 04:09 scaler2017

when I execute: python ./ctpn/demo.py,there is an error: text-detection-ctpn-master\lib\utils_init_.py", line 4, in from . import bbox ImportError: cannot import name 'bbox'. Is anybody can help me, or teach me how to fix the error? Thank a lot.

scaler2017 avatar Sep 19 '18 10:09 scaler2017

in step 5 (4) : there is no file "path/lib/utils_init.py" on my computer. please help!

DaisyLoveU avatar Oct 09 '18 09:10 DaisyLoveU

step3 create a new python file and include only the following codes? import numpy as np from distutils.core import setup from Cython.Build import cythonize from distutils.extension import Extension numpy_include = np.get_include() setup(ext_modules=cythonize("bbox.pyx"),include_dirs=[numpy_include]) setup(ext_modules=cythonize("cython_nms.pyx"),include_dirs=[numpy_include])

wangshengkui avatar Oct 22 '18 13:10 wangshengkui