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

ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (5,) + inhomogeneous part. #194

Open
HardikJain02 opened this issue Jun 25, 2023 · 3 comments · May be fixed by #214

Comments

@HardikJain02
Copy link

HardikJain02 commented Jun 25, 2023

I crash into this error while executing
python test.py --trained_model=craft_mlt_25k.pth --refiner_model=craft_refiner_CTW1500.pth --test_folder=myfolder --refine

Traceback (most recent call last):
File "C:\code\CRAFT-pytorch\test.py", line 165, in
bboxes, polys, score_text = test_net(net, image, args.text_threshold, args.link_threshold, args.low_text, args.cuda, args.poly, refine_net)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\code\CRAFT-pytorch\test.py", line 106, in test_net
polys = craft_utils.adjustResultCoordinates(polys, ratio_w, ratio_h)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\code\CRAFT-pytorch\craft_utils.py", line 251, in adjustResultCoordinates
polys = np.array(polys)
^^^^^^^^^^^^^^^
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (5,) + inhomogeneous part.

@HardikJain02
Copy link
Author

GPT fixed the issue for now:

def adjustResultCoordinates(polys, ratio_w, ratio_h, ratio_net=2): if len(polys) > 0: for k in range(len(polys)): if polys[k] is not None: polys[k] *= np.array([ratio_w * ratio_net, ratio_h * ratio_net]) return polys

Any better solution?

@dungviet112
Copy link

I changed numpy version to 1.23.0 and it worked for me

@HordesOfGhost
Copy link

def adjustResultCoordinates(polys, ratio_w, ratio_h, ratio_net=2): if len(polys) > 0: polys_filtered = [poly for poly in polys if poly is not None] # Added Line polys = np.array(polys_filtered) for k in range(len(polys)): if polys[k] is not None: polys[k] *= (ratio_w * ratio_net, ratio_h * ratio_net) return polys
Replace the above code in site-packages\craft_text_detector\craft_utils.py to solve the inhomogeneous array problem.

eshan1347 added a commit to eshan1347/CRAFT-pytorch that referenced this issue Oct 4, 2024
…n of array incompatible types, which was causing the error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants