Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

error: (-215:Assertion failed) ld.inputBlobs[0]->total() == total(shapes[index]) in function 'cv::dnn::dnn4_v20180917::BlobManager::allocateBlobsForLayer

I wish to use the EAST text detector using Python (on Windows 10) and following this tutorial. However when working with some images it fails systematically with the following error:

cv2.error: OpenCV(4.0.0) C:\projects\opencv-python\opencv\modules\dnn\src\dnn.cpp:835: error: (-215:Assertion failed) ld.inputBlobs[0]->total() == total(shapes[index]) in function 'cv::dnn::dnn4_v20180917::BlobManager::allocateBlobsForLayer'

I cannot tell what characteristics make an image fail or not. Here is the code to reproduce the error (and an example of a troublesome image can be downloaded from here):

# sFileName is the path to the image, previously set
oInputImage = cv.imread(sFileName)
aiShape = oInputImage.shape
(iH, iW) = aiShape[:2]
iRequiredUnit = 32

# check if the image height is enough
iHr = iH % iRequiredUnit
iBottom = 0
iHr = iH % iRequiredUnit
if 0 < iHr:
    # calculate how much padding is necessary
    iBottom = iRequiredUnit - iHr

# check if the image width is enough
iRight = 0
iWr = iW % iRequiredUnit
if 0 < iWr:
    # calculate how much padding is necessary
    iRight = iRequiredUnit - iWr

if iBottom > 0 or iRight > 0:
    # add padding to make the image proportions correct
    oImage = cv.copyMakeBorder(
        src=oInputImage,
        top=iTop,
        bottom=iBottom,
        left=iLeft,
        right=iRight,
        borderType=cv.BORDER_CONSTANT,
        value=[0, 0, 0]
        )
    else:
    # no need to add padding
    oImage = oInputImage.copy()

(iH, iW) = oImage.shape[:2])

ib, ig, ir, _ = cv.mean(oImage)
oBlob = cv.dnn.blobFromImage(
        oImage, 1.0, (iW, iH), (ib, ig, ir),
        swapRB=True, crop=False
)

# load the EAST network
# EAST_path initialized appropriately previously
oNet = cv.dnn.readNet(sEAST_path)
oNet.setInput(oBlob)
asLayerNames = [
        "feature_fusion/Conv_7/Sigmoid",
        "feature_fusion/concat_3"]
(afScores, aoGeometry) = oNet.forward(asLayerNames)

The last line causes the error.

I already posted a request on stack overflow (sorry for cross posting), but I received no answer and I was about to open an issue on github, but there I was invited to post here first.

Any idea on how to solve/prevent the issue?

error: (-215:Assertion failed) ld.inputBlobs[0]->total() == total(shapes[index]) in function 'cv::dnn::dnn4_v20180917::BlobManager::allocateBlobsForLayer

I wish to use the EAST text detector using Python (on Windows 10) and following this tutorial. However when working with some images it fails systematically with the following error:

cv2.error: OpenCV(4.0.0) C:\projects\opencv-python\opencv\modules\dnn\src\dnn.cpp:835: error: (-215:Assertion failed) ld.inputBlobs[0]->total() == total(shapes[index]) in function 'cv::dnn::dnn4_v20180917::BlobManager::allocateBlobsForLayer'

I cannot tell what characteristics make an image fail or not. Here is the code to reproduce the error (and an example of a troublesome image can be downloaded from here):

# sFileName is the path to the image, previously set
oInputImage = cv.imread(sFileName)
aiShape = oInputImage.shape
(iH, iW) = aiShape[:2]
iRequiredUnit = 32

# check if the image height is enough
iHr = iH % iRequiredUnit
iBottom = 0
iHr = iH % iRequiredUnit
if 0 < iHr:
    # calculate how much padding is necessary
    iBottom = iRequiredUnit - iHr

# check if the image width is enough
iRight = 0
iWr = iW % iRequiredUnit
if 0 < iWr:
    # calculate how much padding is necessary
    iRight = iRequiredUnit - iWr

if iBottom > 0 or iRight > 0:
    # add padding to make the image proportions correct
    oImage = cv.copyMakeBorder(
        src=oInputImage,
        top=iTop,
        bottom=iBottom,
        left=iLeft,
        right=iRight,
        borderType=cv.BORDER_CONSTANT,
        value=[0, 0, 0]
        )
    else:
    # no need to add padding
    oImage = oInputImage.copy()

(iH, iW) = oImage.shape[:2])

ib, ig, ir, _ = cv.mean(oImage)
oBlob = cv.dnn.blobFromImage(
        oImage, 1.0, (iW, iH), (ib, ig, ir),
        swapRB=True, crop=False
)

# load the EAST network
# EAST_path initialized appropriately previously
oNet = cv.dnn.readNet(sEAST_path)
oNet.setInput(oBlob)
asLayerNames = [
        "feature_fusion/Conv_7/Sigmoid",
        "feature_fusion/concat_3"]
(afScores, aoGeometry) = oNet.forward(asLayerNames)

The last line causes the error.

I already posted a request on stack overflow (sorry for cross posting), but I received no answer and I was about to open an issue on github, but there I was invited to post here first.

Any idea on how to solve/prevent the issue?

error: (-215:Assertion failed) ld.inputBlobs[0]->total() == total(shapes[index]) in function 'cv::dnn::dnn4_v20180917::BlobManager::allocateBlobsForLayerEAST dnn.forward Assertion failed

I wish to use the EAST text detector using Python (on Windows 10) and following this tutorial. However when working with some images it fails systematically with the following error:

cv2.error: OpenCV(4.0.0) C:\projects\opencv-python\opencv\modules\dnn\src\dnn.cpp:835: error: (-215:Assertion failed) ld.inputBlobs[0]->total() == total(shapes[index]) in function 'cv::dnn::dnn4_v20180917::BlobManager::allocateBlobsForLayer'

I cannot tell what characteristics make an image fail or not. Here is the code to reproduce the error (and an example of a troublesome image can be downloaded from here):

# sFileName is the path to the image, previously set
oInputImage = cv.imread(sFileName)
aiShape = oInputImage.shape
(iH, iW) = aiShape[:2]
iRequiredUnit = 32

# check if the image height is enough
iHr = iH % iRequiredUnit
iBottom = 0
iHr = iH % iRequiredUnit
if 0 < iHr:
    # calculate how much padding is necessary
    iBottom = iRequiredUnit - iHr

# check if the image width is enough
iRight = 0
iWr = iW % iRequiredUnit
if 0 < iWr:
    # calculate how much padding is necessary
    iRight = iRequiredUnit - iWr

if iBottom > 0 or iRight > 0:
    # add padding to make the image proportions correct
    oImage = cv.copyMakeBorder(
        src=oInputImage,
        top=iTop,
        bottom=iBottom,
        left=iLeft,
        right=iRight,
        borderType=cv.BORDER_CONSTANT,
        value=[0, 0, 0]
        )
    else:
    # no need to add padding
    oImage = oInputImage.copy()

(iH, iW) = oImage.shape[:2])

ib, ig, ir, _ = cv.mean(oImage)
oBlob = cv.dnn.blobFromImage(
        oImage, 1.0, (iW, iH), (ib, ig, ir),
        swapRB=True, crop=False
)

# load the EAST network
# EAST_path initialized appropriately previously
oNet = cv.dnn.readNet(sEAST_path)
oNet.setInput(oBlob)
asLayerNames = [
        "feature_fusion/Conv_7/Sigmoid",
        "feature_fusion/concat_3"]
(afScores, aoGeometry) = oNet.forward(asLayerNames)

The last line causes the error.

begin EDIT 0

I tried following the examplehttps://github.com/opencv/opencv/blob/master/samples/dnn/text_detection.py) kindly indicated by *berak but with no success, since most of the relevant differences take place after the call of net.forward. I also tried providing smaller sizes in blobFromImage to avoid the need for the copyMakeBorder part, but if the newly specified size is too small the detection has a lower precision (tried on other images too).

end EDIT 0

I already posted a request on stack overflow (sorry for cross posting), but I received no answer and I was about to open an issue on github, but there I was invited to post here first.

Any idea on how to solve/prevent the issue?

EAST dnn.forward Assertion failed

I wish to use the EAST text detector using Python (on Windows 10) and following this tutorial. However when working with some images it fails systematically with the following error:

cv2.error: OpenCV(4.0.0) C:\projects\opencv-python\opencv\modules\dnn\src\dnn.cpp:835: error: (-215:Assertion failed) ld.inputBlobs[0]->total() == total(shapes[index]) in function 'cv::dnn::dnn4_v20180917::BlobManager::allocateBlobsForLayer'

I cannot tell what characteristics make an image fail or not. Here is the code to reproduce the error (and an example of a troublesome image can be downloaded from here):

# sFileName is the path to the image, previously set
oInputImage = cv.imread(sFileName)
aiShape = oInputImage.shape
(iH, iW) = aiShape[:2]
iRequiredUnit = 32

# check if the image height is enough
iHr = iH % iRequiredUnit
iBottom = 0
iHr = iH % iRequiredUnit
if 0 < iHr:
    # calculate how much padding is necessary
    iBottom = iRequiredUnit - iHr

# check if the image width is enough
iRight = 0
iWr = iW % iRequiredUnit
if 0 < iWr:
    # calculate how much padding is necessary
    iRight = iRequiredUnit - iWr

if iBottom > 0 or iRight > 0:
    # add padding to make the image proportions correct
    oImage = cv.copyMakeBorder(
        src=oInputImage,
        top=iTop,
        bottom=iBottom,
        left=iLeft,
        right=iRight,
        borderType=cv.BORDER_CONSTANT,
        value=[0, 0, 0]
        )
    else:
    # no need to add padding
    oImage = oInputImage.copy()

(iH, iW) = oImage.shape[:2])

ib, ig, ir, _ = cv.mean(oImage)
oBlob = cv.dnn.blobFromImage(
        oImage, 1.0, (iW, iH), (ib, ig, ir),
        swapRB=True, crop=False
)

# load the EAST network
# EAST_path initialized appropriately previously
oNet = cv.dnn.readNet(sEAST_path)
oNet.setInput(oBlob)
asLayerNames = [
        "feature_fusion/Conv_7/Sigmoid",
        "feature_fusion/concat_3"]
(afScores, aoGeometry) = oNet.forward(asLayerNames)

The last line causes the error.

begin EDIT 0

I tried following the examplehttps://github.com/opencv/opencv/blob/master/samples/dnn/text_detection.py) kindly indicated by *berak but with no success, since most of the relevant differences take place after the call of net.forward. I also tried providing smaller sizes in blobFromImage to avoid the need for the copyMakeBorder part, but if the newly specified size is too small the detection has a lower precision (tried on other images too).

end EDIT 0

I already posted a request on stack overflow (sorry for cross posting), but I received no answer and I was about to open an issue on github, but there I was invited to post here first.

Any idea on how to solve/prevent the issue?

EAST dnn.forward Assertion failed

I wish to use the EAST text detector using Python (on Windows 10) 10 with 16 GB RAM) and following this tutorial. However when working with some images it fails systematically with the following error:

cv2.error: OpenCV(4.0.0) C:\projects\opencv-python\opencv\modules\dnn\src\dnn.cpp:835: error: (-215:Assertion failed) ld.inputBlobs[0]->total() == total(shapes[index]) in function 'cv::dnn::dnn4_v20180917::BlobManager::allocateBlobsForLayer'

I cannot tell what characteristics make an image fail or not. Here is the code to reproduce the error (and an example of a troublesome image can be downloaded from here):

# sFileName is the path to the image, previously set
oInputImage = cv.imread(sFileName)
aiShape = oInputImage.shape
(iH, iW) = aiShape[:2]
iRequiredUnit = 32

# check if the image height is enough
iHr = iH % iRequiredUnit
iBottom = 0
iHr = iH % iRequiredUnit
if 0 < iHr:
    # calculate how much padding is necessary
    iBottom = iRequiredUnit - iHr

# check if the image width is enough
iRight = 0
iWr = iW % iRequiredUnit
if 0 < iWr:
    # calculate how much padding is necessary
    iRight = iRequiredUnit - iWr

if iBottom > 0 or iRight > 0:
    # add padding to make the image proportions correct
    oImage = cv.copyMakeBorder(
        src=oInputImage,
        top=iTop,
        bottom=iBottom,
        left=iLeft,
        right=iRight,
        borderType=cv.BORDER_CONSTANT,
        value=[0, 0, 0]
        )
    else:
    # no need to add padding
    oImage = oInputImage.copy()

(iH, iW) = oImage.shape[:2])

ib, ig, ir, _ = cv.mean(oImage)
oBlob = cv.dnn.blobFromImage(
        oImage, 1.0, (iW, iH), (ib, ig, ir),
        swapRB=True, crop=False
)

# load the EAST network
# EAST_path initialized appropriately previously
oNet = cv.dnn.readNet(sEAST_path)
oNet.setInput(oBlob)
asLayerNames = [
        "feature_fusion/Conv_7/Sigmoid",
        "feature_fusion/concat_3"]
(afScores, aoGeometry) = oNet.forward(asLayerNames)

The last line causes the error.

begin EDIT 0

I tried following the examplehttps://github.com/opencv/opencv/blob/master/samples/dnn/text_detection.py) kindly indicated by *berak but with no success, since most of the relevant differences take place after the call of net.forward. I also tried providing smaller sizes in blobFromImage to avoid the need for the copyMakeBorder part, but if the newly specified size is too small the detection has a lower precision (tried on other images too).

end EDIT 0

I already posted a request on stack overflow (sorry for cross posting), but I received no answer and I was about to open an issue on github, but there I was invited to post here first.

begin EDIT 1

I made some experiments to see how memory occupation could affect the execution. Here are some results, to be read as follows:

  • rows:
    • first and second row show the height and width passed as parameters to the openCV example
    • next rows contain the memory occupation at various stages of execution
  • columns:
    • the first column states the phase at which memory was measured
    • the remaining ones show the memory occupation by the program, expressed in GB. MIssing values are for those cases where EAST crashed with the error reported above

+------------------------------------+-------+-------+-------+-------+-------+-------+--------+-------+ | height | 320 | 640 | 1024 | 2048 | 4096 | 8192 | 4096 | 4544 | +------------------------------------+-------+-------+-------+-------+-------+-------+--------+-------+ | width | 320 | 640 | 1024 | 2048 | 4096 | 4096 | 30240 | 30272 | +------------------------------------+-------+-------+-------+-------+-------+-------+--------+-------+ | Memory at beginning: | 0.031 | 0.031 | 0.031 | 0.031 | 0.031 | 0.031 | 0.031 | 0.179 | +------------------------------------+-------+-------+-------+-------+-------+-------+--------+-------+ | Memory after loading image: | 0.179 | 0.179 | 0.179 | 0.179 | 0.179 | 0.179 | 0.179 | 1.843 | +------------------------------------+-------+-------+-------+-------+-------+-------+--------+-------+ | Memory before creating blob: | 1.844 | 1.844 | 1.843 | 1.843 | 1.844 | 1.843 | 1.844 | 3.381 | +------------------------------------+-------+-------+-------+-------+-------+-------+--------+-------+ | Memory after creating blob: | 1.845 | 1.849 | 1.856 | 1.891 | 2.033 | 2.220 | 3.229 | 4.918 | +------------------------------------+-------+-------+-------+-------+-------+-------+--------+-------+ | Memory before running net.forward: | 1.847 | 1.854 | 1.868 | 1.938 | 2.220 | 2.595 | 4.613 | | +------------------------------------+-------+-------+-------+-------+-------+-------+--------+-------+ | Memory after running net.forward: | 1.964 | 2.049 | 2.227 | 3.103 | 4.388 | 8.681 | 12.613 | | +------------------------------------+-------+-------+-------+-------+-------+-------+--------+-------+ I also followed the execution with the task manager and for those cases where dnn crashed, the memory footprint did not raise above 6 GB, so it looks like memory availability is not the culprit (although it is a relevant issue). end EDIT 1

Any idea on how to solve/prevent the issue?

EAST dnn.forward Assertion failed

I wish to use the EAST text detector using Python (on Windows 10 with 16 GB RAM) and following this tutorial. However when working with some images it fails systematically with the following error:

cv2.error: OpenCV(4.0.0) C:\projects\opencv-python\opencv\modules\dnn\src\dnn.cpp:835: error: (-215:Assertion failed) ld.inputBlobs[0]->total() == total(shapes[index]) in function 'cv::dnn::dnn4_v20180917::BlobManager::allocateBlobsForLayer'

I cannot tell what characteristics make an image fail or not. Here is the code to reproduce the error (and an example of a troublesome image can be downloaded from here): ...it's a pretty big image, i.e., width = 30253 and height = 4537):

# sFileName is the path to the image, previously set
oInputImage = cv.imread(sFileName)
aiShape = oInputImage.shape
(iH, iW) = aiShape[:2]
iRequiredUnit = 32

# check if the image height is enough
iHr = iH % iRequiredUnit
iBottom = 0
iHr = iH % iRequiredUnit
if 0 < iHr:
    # calculate how much padding is necessary
    iBottom = iRequiredUnit - iHr

# check if the image width is enough
iRight = 0
iWr = iW % iRequiredUnit
if 0 < iWr:
    # calculate how much padding is necessary
    iRight = iRequiredUnit - iWr

if iBottom > 0 or iRight > 0:
    # add padding to make the image proportions correct
    oImage = cv.copyMakeBorder(
        src=oInputImage,
        top=iTop,
        bottom=iBottom,
        left=iLeft,
        right=iRight,
        borderType=cv.BORDER_CONSTANT,
        value=[0, 0, 0]
        )
    else:
    # no need to add padding
    oImage = oInputImage.copy()

(iH, iW) = oImage.shape[:2])

ib, ig, ir, _ = cv.mean(oImage)
oBlob = cv.dnn.blobFromImage(
        oImage, 1.0, (iW, iH), (ib, ig, ir),
        swapRB=True, crop=False
)

# load the EAST network
# EAST_path initialized appropriately previously
oNet = cv.dnn.readNet(sEAST_path)
oNet.setInput(oBlob)
asLayerNames = [
        "feature_fusion/Conv_7/Sigmoid",
        "feature_fusion/concat_3"]
(afScores, aoGeometry) = oNet.forward(asLayerNames)

The last line causes the error.

begin EDIT 0

I tried following the example kindly indicated by berak but with no success, since most of the relevant differences take place after the call of net.forward. I also tried providing smaller sizes in blobFromImage to avoid the need for the copyMakeBorder part, but if the newly specified size is too small the detection has a lower precision (tried on other images too).

end EDIT 0

I already posted a request on stack overflow (sorry for cross posting), but I received no answer and I was about to open an issue on github, but there I was invited to post here first.

begin EDIT 1

I made some experiments to see how memory occupation could affect the execution. Here are some results, to be read as follows:

  • rows:
      rows:
    • first and second row show the height and width passed as parameters to the openCV example
    • next rows contain the memory occupation at various stages of execution
  • columns:
    • columns:
    • the first column states the phase at which memory was measured
    • the remaining ones show the memory occupation by the program, expressed in GB. MIssing values are for those cases where EAST crashed with the error reported above

+------------------------------------+-------+-------+-------+-------+-------+-------+--------+-------+ |

  1. height | 320 | 640 | 1024 | 2048 | 4096 | 8192 | 4096 | 4544 | +------------------------------------+-------+-------+-------+-------+-------+-------+--------+-------+ | 4544
  2. width | 320 | 640 | 1024 | 2048 | 4096 | 4096 | 30240 | 30272 | +------------------------------------+-------+-------+-------+-------+-------+-------+--------+-------+ | 30272
  3. Memory at beginning: | 0.031 | 0.031 | 0.031 | 0.031 | 0.031 | 0.031 | 0.031 | 0.179 | +------------------------------------+-------+-------+-------+-------+-------+-------+--------+-------+ | 0.179
  4. Memory after loading image: | 0.179 | 0.179 | 0.179 | 0.179 | 0.179 | 0.179 | 0.179 | 1.843 | +------------------------------------+-------+-------+-------+-------+-------+-------+--------+-------+ | 1.843
  5. Memory before creating blob: | 1.844 | 1.844 | 1.843 | 1.843 | 1.844 | 1.843 | 1.844 | 3.381 | +------------------------------------+-------+-------+-------+-------+-------+-------+--------+-------+ | 3.381
  6. Memory after creating blob: | 1.845 | 1.849 | 1.856 | 1.891 | 2.033 | 2.220 | 3.229 | 4.918 | +------------------------------------+-------+-------+-------+-------+-------+-------+--------+-------+ | 4.918
  7. Memory before running net.forward: | 1.847 | 1.854 | 1.868 | 1.938 | 2.220 | 2.595 | 4.613 | | +------------------------------------+-------+-------+-------+-------+-------+-------+--------+-------+ | 4.613
  8. Memory after running net.forward: | 1.964 | 2.049 | 2.227 | 3.103 | 4.388 | 8.681 | 12.613 | | +------------------------------------+-------+-------+-------+-------+-------+-------+--------+-------+ 12.613

(please forgive the bad indentation of the table, I tried many formatting schemes and none was satisfying. If you know how to improve it's rendering please drop me a comment and I'd be glad to do it)

I also followed the execution with the task manager and for those cases where dnn dnn crashed, the memory footprint did not raise above 6 GB, so it looks like memory availability is not the culprit (although it is a relevant issue). issue).

end EDIT 1

Any idea on how to solve/prevent the issue?