AntonMu/TrainYourOwnYOLO

self._traceback = tf_stack.extract_stack()

joaoalves10 opened this issue · 0 comments

Hi @AntonMu i am having an issue with your repository for a while whenener i try to adpat the detector to my project.
My project aims to detect cars via aerial images taken by an UAV. The detection needs to be real-time.
So, i start by following all your steps to create my own dataset and to train it. I was able to do it all with sucess, which means that right now i have your repository with my dataset and the detector is working fine with the weights that i train and the images that i selected to test.

After this i tried to adapt your Detector.py script to a simpler one that just received an image and detect it, as shown below:

  _from PIL import Image
  import cv2
  from keras_yolo3.yolo import YOLO
  
  def simple():
      yolo = YOLO(
          **{
              "model_path": '/home/joao/catkin_ws/src/offboard_tutorials/src/offboard_control_pkg/lei_controlo_scripts/Data/Model_Weights/trained_weights_final.h5',
              "anchors_path": '/home/joao/catkin_ws/src/offboard_tutorials/src/offboard_control_pkg/lei_controlo_scripts/simulacao_completa/keras_yolo3/model_data/yolo_anchors.txt',
              "classes_path": '/home/joao/catkin_ws/src/offboard_tutorials/src/offboard_control_pkg/lei_controlo_scripts/Data/Model_Weights/data_classes.txt',
              "score": 0.25,
              "gpu_num": 1,
              "model_image_size": (416, 416),
          }
      )
  
      fn = "/home/joao/catkin_ws/src/offboard_tutorials/src/offboard_control_pkg/lei_controlo_scripts/Data/Source_Images/Test_Images/1642513427.jpg"
      image_matrix = cv2.imread(fn)
      fileimage = Image.fromarray(image_matrix)
      print('\n\n\n\n start detection \n\n\n\n\n')
      out_pred, det_image = yolo.detect_image(fileimage, show_stats=False)
      print('\n\n\n\n finished first run\n\n\n\n\n')
      print(out_pred)
  
  if __name__ == '__main__':
      # main()
      simple()_

However, when i try to run it it gives me the following error:

Traceback (most recent call last):
  File "/home/joao/env/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 1365, in _do_call
    return fn(*args)
  File "/home/joao/env/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 1350, in _run_fn
    target_list, run_metadata)
  File "/home/joao/env/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 1443, in _call_tf_sessionrun
    run_metadata)
tensorflow.python.framework.errors_impl.UnimplementedError: The Conv2D op currently does not support grouped convolutions on the CPU. A grouped convolution was attempted to be run because the input depth of 1024 does not match the filter input depth of 1
	 [[{{node conv2d_58/Conv2D}}]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/joao/catkin_ws/src/offboard_tutorials/src/offboard_control_pkg/lei_controlo_scripts/simulacao_completa/image_car_detector_com_video.py", line 150, in <module>
    simple()
  File "/home/joao/catkin_ws/src/offboard_tutorials/src/offboard_control_pkg/lei_controlo_scripts/simulacao_completa/image_car_detector_com_video.py", line 144, in simple
    out_pred, det_image = yolo.detect_image(fileimage, show_stats=False)
  File "/home/joao/catkin_ws/src/offboard_tutorials/src/offboard_control_pkg/lei_controlo_scripts/simulacao_completa/keras_yolo3/yolo.py", line 162, in detect_image
    K.learning_phase(): 0,
  File "/home/joao/env/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 956, in run
    run_metadata_ptr)
  File "/home/joao/env/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 1180, in _run
    feed_dict_tensor, options, run_metadata)
  File "/home/joao/env/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 1359, in _do_run
    run_metadata)
  File "/home/joao/env/lib/python3.6/site-packages/tensorflow_core/python/client/session.py", line 1384, in _do_call
    raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.UnimplementedError: The Conv2D op currently does not support grouped convolutions on the CPU. A grouped convolution was attempted to be run because the input depth of 1024 does not match the filter input depth of 1
	 [[node conv2d_58/Conv2D (defined at /env/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py:1748) ]]

Original stack trace for 'conv2d_58/Conv2D':
  File "/catkin_ws/src/offboard_tutorials/src/offboard_control_pkg/lei_controlo_scripts/simulacao_completa/image_car_detector_com_video.py", line 150, in <module>
    simple()
  File "/catkin_ws/src/offboard_tutorials/src/offboard_control_pkg/lei_controlo_scripts/simulacao_completa/image_car_detector_com_video.py", line 136, in simple
    "model_image_size": (416, 416),
  File "/catkin_ws/src/offboard_tutorials/src/offboard_control_pkg/lei_controlo_scripts/simulacao_completa/keras_yolo3/yolo.py", line 49, in __init__
    self.boxes, self.scores, self.classes = self.generate()
  File "/catkin_ws/src/offboard_tutorials/src/offboard_control_pkg/lei_controlo_scripts/simulacao_completa/keras_yolo3/yolo.py", line 83, in generate
    Input(shape=(None, None, 3)), num_anchors // 3, num_classes
  File "/catkin_ws/src/offboard_tutorials/src/offboard_control_pkg/lei_controlo_scripts/simulacao_completa/keras_yolo3/yolo3/model.py", line 90, in yolo_body
    x, y1 = make_last_layers(darknet.output, 512, num_anchors * (num_classes + 5))
  File "/catkin_ws/src/offboard_tutorials/src/offboard_control_pkg/lei_controlo_scripts/simulacao_completa/keras_yolo3/yolo3/model.py", line 83, in make_last_layers
    )(x)
  File "/catkin_ws/src/offboard_tutorials/src/offboard_control_pkg/lei_controlo_scripts/simulacao_completa/keras_yolo3/yolo3/utils.py", line 21, in <lambda>
    return reduce(lambda f, g: lambda *a, **kw: g(f(*a, **kw)), funcs)
  File "/env/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/base_layer.py", line 854, in __call__
    outputs = call_fn(cast_inputs, *args, **kwargs)
  File "/env/lib/python3.6/site-packages/tensorflow_core/python/keras/layers/convolutional.py", line 197, in call
    outputs = self._convolution_op(inputs, self.kernel)
  File "/env/lib/python3.6/site-packages/tensorflow_core/python/ops/nn_ops.py", line 1134, in __call__
    return self.conv_op(inp, filter)
  File "/env/lib/python3.6/site-packages/tensorflow_core/python/ops/nn_ops.py", line 639, in __call__
    return self.call(inp, filter)
  File "/env/lib/python3.6/site-packages/tensorflow_core/python/ops/nn_ops.py", line 238, in __call__
    name=self.name)
  File "/env/lib/python3.6/site-packages/tensorflow_core/python/ops/nn_ops.py", line 2010, in conv2d
    name=name)
  File "/env/lib/python3.6/site-packages/tensorflow_core/python/ops/gen_nn_ops.py", line 1071, in conv2d
    data_format=data_format, dilations=dilations, name=name)
  File "/env/lib/python3.6/site-packages/tensorflow_core/python/framework/op_def_library.py", line 794, in _apply_op_helper
    op_def=op_def)
  File "/env/lib/python3.6/site-packages/tensorflow_core/python/util/deprecation.py", line 507, in new_func
    return func(*args, **kwargs)
  File "/env/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py", line 3357, in create_op
    attrs, op_def, compute_device)
  File "/env/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py", line 3426, in _create_op_internal
    op_def=op_def)
  File "/env/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py", line 1748, in __init__
    self._traceback = tf_stack.extract_stack()

I put this script in the same folder as the Detector.py, and i am using the weights that i trained and were working with your repository.

Can you help me?

Thank you