hhk7734 / tensorflow-yolov4

YOLOv4 Implemented in Tensorflow 2.
MIT License
136 stars 75 forks source link

getting error: AttributeError: 'tuple' object has no attribute 'numpy' while running yolo.inference() after loading weights #71

Closed yosefyehoshua closed 3 years ago

yosefyehoshua commented 3 years ago

I'm trying to get prediction from preloaded weights from this repo, and get some inputs about the model.

I use yolov4-tiny-relu-tpu.cfg config & yolov4-tiny-relu.weights and v3 of this repo but while running this code:

from yolov4.tf import YOLOv4, YOLODataset, create_mAP_input_files

WORKING_DIR ="/path/to/yolov4_tf24/"

yolo = YOLOv4()

yolo.config.parse_names(WORKING_DIR + "test/coco.names")
yolo.config.parse_cfg(WORKING_DIR + "config/yolov4-tiny-relu-tpu.cfg")

yolo.make_model()
yolo.load_weights(
     WORKING_DIR + "weights/yolov4-tiny-relu.weights", weights_type="yolo"
)

yolo.summary()

yolo.inference(media_path = "/path/to/image.png",
                         is_image=True,
)

im getting this error:

Exception has occurred: AttributeError       (note: full exception trace is shown but execution is paused at: _run_module_as_main)
'tuple' object has no attribute 'numpy'

  File "/usr/local/lib/python3.8/dist-packages/yolov4/tf/__init__.py", line 123, in <listcomp>
    c.numpy().astype(np.float32, copy=False) for c in candidates
  File "/usr/local/lib/python3.8/dist-packages/yolov4/tf/__init__.py", line 122, in predict
    candidates = [
  File "/usr/local/lib/python3.8/dist-packages/yolov4/common/base_class.py", line 176, in inference
    bboxes = self.predict(frame)
  File "/mnt/hdNear/workspace/josef/input_size_project/yolov4_tf24/yolov4_model_test.py", line 17, in <module>
    yolo.inference(media_path = "/mnt/hdNear/workspace/josef/input_size_project/yolov4_tf24/test/padded_vs_orig/832x832/DualAir_00133_r2_2_000231_003.png",
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/usr/lib/python3.8/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib/python3.8/runpy.py", line 265, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main (Current frame)
    return _run_code(code, main_globals, None,

the model returns array of tuples with tensors in them, and try to turn them to a numpy array. I would be happy for some help.

hhk7734 commented 3 years ago

config/yolov4-tiny-relu-tpu.cfg is used only when creating a model for use in edgetpu. use yolov4-tiny-relu.cfg