-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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
OpenCL error codes, then junk output -- possibly a build issue? #124
Comments
I'm seeing something very similar. First time I run Tesseract after deleting tesseract_opencl_profile_devices.dat, I get the following: _START_** [DS] Device: "Tesla K40c" (OpenCL) evaluation... [DS] Device: "(null)" (Native) evaluation... _STOP_********** Running after that I get: _START_********** _STOP_*********** This creates the txt file, but it's just junk, maybe a few random characters. For a long time I was also seeing the 'Error in boxClipToRectangle: box outside rectangle' sort of errors that axfelix was seeing. If I run it with the CPU device like this: TESSERACT_OPENCL_DEVICE=2 tesseract ESub.png ESubPng ...it works perfectly. Great OCR output. I have done everything I can imagine, including rebuilding Tesseract several times, using jpg, png and tif input files and rebuilding Leptonica. The nvidia drivers are the latest and OpenCL is the latest. Any ideas? |
Still working on the problem. Here's some information that will hopefully make it easier for someone to solve before I spend another day tracking it down. I have two test cases using the same source file. Doesn't matter if the source is png or tif, same bad results. Tesseract correctly identifies that I have a Tesla K40c as device 1. The CPU is device 2. The call I'm making is either: In the file baseapi.cpp in function TessBaseAPI::ProcessPage() I put in code to save the image before and after the call to GetThresholdedImage() like so:
In the CPU version both before and after images look correct, showing the same text and formatting. In the GPU OpenCL version 'before' is fine, but the 'after' version is seriously sheared when the source image has non-binary dimensions. It looks like the pitch is being miscalculated. The source image was 1721 x 1238 pixels. In this case the OCR failed completely of course. On an educated hunch I resized the the same image to 2048 x 1024. Now the shearing is gone, The characters in the image are somewhat recognizable. There is still a problem, the letters are all munged, almost like letters are being overlaid on top of each other or something. I will send the two bad output images if you tell me where. |
I swear I've seen this particular image corruption before, when I was working on the pdf output module. I wish I could remember what it was. |
Anything else that can be done to help debug? I have a vested interest in getting a working OpenCL build before the end of January... |
I speculate we had a Leptonica bug, fixed it, but the fix never got propagated to the OpenCL-ified mini-fork of Leptonica that sits inside Tesseract. I think the way to go is look inside the thresholding call and keep comparing the CPU vs GPU to help isolate where things go different. It's also helpful to look at all data in the pix struct before/after/cpu/gpu to understand better what went wrong. struct Pix
{
l_uint32 w; /* width in pixels */
l_uint32 h; /* height in pixels */
l_uint32 d; /* depth in bits (bpp) */
l_uint32 spp; /* number of samples per pixel */
l_uint32 wpl; /* 32-bit words/line */
l_uint32 refcount; /* reference count (1 if no clones) */
l_int32 xres; /* image res (ppi) in x direction */
/* (use 0 if unknown) */
l_int32 yres; /* image res (ppi) in y direction */
/* (use 0 if unknown) */
l_int32 informat; /* input file format, IFF_* */
l_int32 special; /* special instructions for I/O, etc */
char *text; /* text string associated with pix */
struct PixColormap *colormap; /* colormap (may be null) */
l_uint32 *data; /* the image data */
}; I don't know/remember what this code path is trying to do. Seems odd that Line 1230 in c53add7
|
Yeah, that sure looks like a debug path. New theory is OpenCL turns on some some debugging, which activates faulty debugging code that messes everything up. |
Separate experiment, swap: pixWrite("tessinputAFTER.tif", page_pix, IFF_TIFF_G4); with pixWrite("tessinputAFTER.png", page_pix, IFF_PNG); just to make sure we're not having trouble with writing out your debug image. |
And finally, find the place where the image is first read into Tesseeract and turned into a Pix. See if we already have corruption at that point. |
I can't debug this myself. I still get a segfault on my computer when trying to use OpenCL as per issue #53 . Will be travelling for the rest of the month. Good luck and sorry. |
PR #475 fixes an error with OpenCL which results in these error message:
Maybe it is related to this issue, too. |
Hi folks,
Having trouble getting a working OpenCL build. First run in a new working directory gets upset that there's no opencl_profile_devices.dat:
axfelix@shoebox:~/Desktop$ tesseract test.png out pdf
Tesseract Open Source OCR Engine v3.05.00dev with Leptonica
[DS] Profile file not available (tesseract_opencl_profile_devices.dat); performing profiling.
[DS] Device: "GeForce GTX TITAN X" (OpenCL) evaluation...
[OD] write binary[kernel-GeForce_GTX_TITAN_X.bin] succesfully
[DS] Device: "GeForce GTX TITAN X" (OpenCL) evaluated
[DS] composeRGBPixel: 0.022978 (w=1.2)
[DS] HistogramRect: 0.012700 (w=2.4)
[DS] ThresholdRectToPix: 0.010093 (w=4.5)
[DS] getLineMasksMorph: 0.004402 (w=5.0)
[DS] Score: 0.125484
[DS] Device: "(null)" (Native) evaluation...
[DS] Device: "(null)" (Native) evaluated
[DS] composeRGBPixel: 0.018301 (w=1.2)
[DS] HistogramRect: 0.060059 (w=2.4)
[DS] ThresholdRectToPix: 0.016802 (w=4.5)
[DS] getLineMasksMorph: 0.110437 (w=5.0)
[DS] Score: 0.793896
[DS] Scores written to file (tesseract_opencl_profile_devices.dat).
[DS] Device[1] 1:GeForce GTX TITAN X score is 0.125484
[DS] Device[2] 0:(null) score is 0.793896
[DS] Selected Device[1]: "GeForce GTX TITAN X" (OpenCL)
OpenCL error code is -38 at when clSetKernelArg imageBuffer .
OpenCL error code is -38 at when clSetKernelArg tmpHistogramBuffer .
OpenCL error code is -38 at when clSetKernelArg tmpHistogramBuffer .
OpenCL error code is -38 at when clSetKernelArg histogramBuffer .
OpenCL error code is -52 at when clEnqueueNDRangeKernel kernel_HistogramRectAllChannels .
OpenCL error code is -52 at when clEnqueueNDRangeKernel kernel_HistogramRectAllChannelsReduction .
OpenCL error code is -38 at when clSetKernelArg imageBuffer .
OpenCL error code is -38 at when clSetKernelArg thresholdsBuffer .
OpenCL error code is -38 at when clSetKernelArg hiValuesBuffer .
OpenCL error code is -38 at when clSetKernelArg pixThBuffer .
OpenCL error code is -52 at when clEnqueueNDRangeKernel kernel_ThresholdRectToPix .
Setting return value to -1
OpenCL error code is -38 at when clSetKernelArg imageBuffer .
OpenCL error code is -38 at when clSetKernelArg tmpHistogramBuffer .
OpenCL error code is -38 at when clSetKernelArg tmpHistogramBuffer .
OpenCL error code is -38 at when clSetKernelArg histogramBuffer .
OpenCL error code is -52 at when clEnqueueNDRangeKernel kernel_HistogramRectAllChannels .
OpenCL error code is -52 at when clEnqueueNDRangeKernel kernel_HistogramRectAllChannelsReduction .
After that, it works (while throwing issues like Error in boxClipToRectangle: box outside rectangle
Error in pixScanForForeground: invalid box) but the output is basically junk. Did I screw something up when compiling?
The text was updated successfully, but these errors were encountered: