hhk7734 / tensorflow-yolov4

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

TypeError when running code #6

Closed vincentkieboom closed 4 years ago

vincentkieboom commented 4 years ago

I'm not able to run the code because of the following errormessage. Please help.

My code:

from yolov4.tf import YOLOv4
yolo = YOLOv4()
yolo.classes = './newtry/coco.names'
yolo.make_model()
yolo.load_weights('./newtry/yolov4.weights', weights_type="yolo")
yolo.inference(media_path="./newtry/test.jpg")

I get the following error when running my code:

TypeError                                 Traceback (most recent call last)
<ipython-input-14-9306638226c6> in <module>
      1 yolo.classes = './newtry/coco.names'
      2 
----> 3 yolo.make_model()
      4 
      5 yolo.load_weights('./newtry/yolov4.weights', weights_type="yolo")

~\anaconda3\lib\site-packages\yolov4\tf\__init__.py in make_model(self)
    165         )
    166         # [batch, height, width, channel]
--> 167         self.model(tf.keras.layers.Input([self.input_size, self.input_size, 3]))
    168 
    169     def load_weights(self, path: str, weights_type: str = "tf"):

~\anaconda3\lib\site-packages\tensorflow\python\keras\engine\base_layer.py in __call__(self, inputs, *args, **kwargs)
    552             # In graph mode, failure to build the layer's graph
    553             # implies a user-side bug. We don't catch exceptions.
--> 554             outputs = self.call(inputs, *args, **kwargs)
    555           else:
    556             try:

~\anaconda3\lib\site-packages\yolov4\model\yolov4.py in call(self, x, training)
    246         s_bboxes = self.conv93(s_bboxes)
    247         # (batch, 3x, 3x, 3, (4 + 1 + num_classes))
--> 248         s_bboxes = self.decode93(s_bboxes, training)
    249 
    250         x2 = self.conv94(x2)

~\anaconda3\lib\site-packages\tensorflow\python\keras\engine\base_layer.py in __call__(self, inputs, *args, **kwargs)
    582           if base_layer_utils.have_all_keras_metadata(inputs):
    583             inputs, outputs = self._set_connectivity_metadata_(
--> 584                 inputs, outputs, args, kwargs)
    585           if hasattr(self, '_set_inputs') and not self.inputs:
    586             # Subclassed network: explicitly set metadata normally set by

~\anaconda3\lib\site-packages\tensorflow\python\keras\engine\base_layer.py in _set_connectivity_metadata_(self, inputs, outputs, args, kwargs)
   1392             'Pass everything else as a keyword argument '
   1393             '(those arguments will not be tracked '
-> 1394             'as inputs to the layer).'.format(self.name))
   1395 
   1396     # If the layer returns tensors from its inputs, unmodified,

TypeError: This layer ("decode") takes a single positional argument in `call()`, which is by convention the `inputs` argument, and only this argument may be specified as a positional argument. Pass everything else as a keyword argument (those arguments will not be tracked as inputs to the layer).
hhk7734 commented 4 years ago

After update yolov4, try again.

python3 -m pip install -U yolov4
vincentkieboom commented 4 years ago

Same error..

hhk7734 commented 4 years ago

What is your tensorflow version?

Edit like below

~\anaconda3\lib\site-packages\yolov4\model\yolov4.py

s_bboxes = self.decode93(s_bboxes, training=training)
...
m_bboxes = self.decode101(m_bboxes, training=training)
...
l_bboxes = self.decode109(l_bboxes, training=training)
hhk7734 commented 4 years ago

python 3.6.9, Linux Ubuntu yolov4 v0.11.0 tensorflow v2.2.0

I tested it now, but I can't make same error.

vincentkieboom commented 4 years ago

What is your tensorflow version?

Edit like below

~\anaconda3\lib\site-packages\yolov4\model\yolov4.py

s_bboxes = self.decode93(s_bboxes, training=training)
...
m_bboxes = self.decode101(m_bboxes, training=training)
...
l_bboxes = self.decode109(l_bboxes, training=training)

After edit I get this error message:


---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-2-9306638226c6> in <module>
      6 
      7 yolo.inference(
----> 8     media_path=".test.jpg")

~\anaconda3\lib\site-packages\yolov4\tf\__init__.py in inference(self, media_path, is_image, cv_waitKey_delay)
    197         if is_image:
    198             frame = cv2.imread(media_path)
--> 199             frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
    200 
    201             prev_time = time.time()

error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

I'm on tf v2.2.0

hhk7734 commented 4 years ago
----> 8     media_path=".test.jpg")

.test.jpg is invalid name. ./test.jpg or /<path>/test.jpg

vincentkieboom commented 4 years ago

Ah indeed, this worked! Thank you!

hhk7734 commented 4 years ago

After modifying the parameters and adding a clear error message output, I will close it. Thanks @vincent1618

hhk7734 commented 4 years ago

tf: add FileNotFoundError in YOLOv4.inference() 45c7516 model: yolov4: modify positional arg to keyword arg 9889f8f