AnimatedDrawings icon indicating copy to clipboard operation
AnimatedDrawings copied to clipboard

AttributeError: 'dict' object has no attribute 'sort' in /examples/image_to_annotations.py

Open chenyenru opened this issue 1 year ago • 0 comments

Hi, when I tried to run my own image by setting up the container and following the tutorial below, it shows an error message.

(animated_drawings) torchserve % cd ../examples (animated_drawings) examples % python image_to_animation.py drawings/garlic.png garlic_out

Here is the error message:

Traceback (most recent call last): File "/Users/chen_yenru/Documents/GitHub/DATASCIENCE/ML/AnimatedDrawings/examples/image_to_animation.py", line 41, in <module> image_to_animation(img_fn, char_anno_dir, motion_cfg_fn, retarget_cfg_fn) File "/Users/chen_yenru/Documents/GitHub/DATASCIENCE/ML/AnimatedDrawings/examples/image_to_animation.py", line 19, in image_to_animation image_to_annotations(img_fn, char_anno_dir) File "/Users/chen_yenru/Documents/GitHub/DATASCIENCE/ML/AnimatedDrawings/examples/image_to_annotations.py", line 59, in image_to_annotations detection_results.sort(key=lambda x: x['score'], reverse=True) ^^^^^^^^^^^^^^^^^^^^^^ AttributeError: 'dict' object has no attribute 'sort'

I think it's because of Python's version difference, where .sort() is only for Python 2.

Yet, when I change it to sort(detection_results, key=lambda x: x['score'], reverse=True), it then returns a type error on the indices.

Here is the error message: Traceback (most recent call last): File "/Users/chen_yenru/Documents/GitHub/DATASCIENCE/ML/AnimatedDrawings/examples/image_to_animation.py", line 41, in <module> image_to_animation(img_fn, char_anno_dir, motion_cfg_fn, retarget_cfg_fn) File "/Users/chen_yenru/Documents/GitHub/DATASCIENCE/ML/AnimatedDrawings/examples/image_to_animation.py", line 19, in image_to_animation image_to_annotations(img_fn, char_anno_dir) File "/Users/chen_yenru/Documents/GitHub/DATASCIENCE/ML/AnimatedDrawings/examples/image_to_annotations.py", line 59, in image_to_annotations sorted(detection_results, key=lambda x: x['score'], reverse=True) File "/Users/chen_yenru/Documents/GitHub/DATASCIENCE/ML/AnimatedDrawings/examples/image_to_annotations.py", line 59, in <lambda> sorted(detection_results, key=lambda x: x['score'], reverse=True) ~^^^^^^^^^ TypeError: string indices must be integers, not 'str'

I'd like to ask how to overcome this problem? Thanks!

chenyenru avatar Apr 18 '23 00:04 chenyenru