0

I'm writing a GUI application with wxpython. The application uses yolo to detect pavement breakage. I use the yolo code to train and detect. It is too time-consuming to load the yolo model, so the GUI will freeze. Therefore, I expect to show a progress bar during loading yolo model with threading.Thread. I can use main thread to load yolo model, but I get a exception during loading yolo model with a new thread.

The error:

Traceback (most recent call last):
  File "C:\Program Files\Python36\lib\contextlib.py", line 99, in __exit__
    self.gen.throw(type, value, traceback)
  File "C:\Users\JH-06\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\framework\ops.py", line 5652, in get_controller
    yield g
  File "d:\code\Python\yoloDetector_v007\src\YOLO\yolo.py", line 76, in generate
    self.yolo_model = load_model(model_path, compile=False)
  File "C:\Program Files\Python36\lib\site-packages\keras\engine\saving.py", line 419, in load_model
    model = _deserialize_model(f, custom_objects, compile)
  File "C:\Program Files\Python36\lib\site-packages\keras\engine\saving.py", line 221, in _deserialize_model
    model_config = f['model_config']
  File "C:\Program Files\Python36\lib\site-packages\keras\utils\io_utils.py", line 302, in __getitem__
    raise ValueError('Cannot create group in read only mode.')
ValueError: Cannot create group in read only mode.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "d:\code\Python\yoloDetector_v007\src\myRoadDamageUtil\myRoadDetectionModel.py", line 166, in init
    self.__m_oVideoDetector.init()
  File "d:\code\Python\yoloDetector_v007\src\myRoadDamageUtil\myVideoDetector.py", line 130, in init
    self.__m_oDetector.init()
  File "d:\code\Python\yoloDetector_v007\src\myRoadDamageUtil\myRoadBreakageDetector.py", line 87, in init
    self.__m_oYoloDetector.init()
  File "d:\code\Python\yoloDetector_v007\src\YOLO\yolo.py", line 46, in init
    self.boxes, self.scores, self.classes = self.generate()
  File "d:\code\Python\yoloDetector_v007\src\YOLO\yolo.py", line 80, in generate
    self.yolo_model.load_weights(self.model_path) # make sure model, anchors and classes match
  File "C:\Program Files\Python36\lib\site-packages\keras\engine\network.py", line 1166, in load_weights
    f, self.layers, reshape=reshape)
  File "C:\Program Files\Python36\lib\site-packages\keras\engine\saving.py", line 1058, in load_weights_from_hdf5_group
    K.batch_set_value(weight_value_tuples)
  File "C:\Program Files\Python36\lib\site-packages\keras\backend\tensorflow_backend.py", line 2470, in batch_set_value
    get_session().run(assign_ops, feed_dict=feed_dict)
  File "C:\Users\JH-06\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\client\session.py", line 950, in run
    run_metadata_ptr)
  File "C:\Users\JH-06\AppData\Roaming\Python\Python36\site-packages\tensorflow\python\client\session.py", line 1098, in _run
    raise RuntimeError('The Session graph is empty.  Add operations to the '
RuntimeError: The Session graph is empty.  Add operations to the graph before calling run().

May somebody give me any suggestion?

1 Answers1

0

When using wxPython with threads, you need to make sure that you are using a thread-safe method to communicate back to the GUI. There are 3 thread-safe methods you can use with wxPython:

  • wx.CallAfter
  • wx.CallLater
  • wx.PostEvent

Check out either of the following articles for more information

Mike Driscoll
  • 32,629
  • 8
  • 45
  • 88
  • The [yolo code](https://github.com/qqwweee/keras-yolo3) isn't written by me, so I'm not sure that all methods are thread-safe in [yolo code](https://github.com/qqwweee/keras-yolo3). – burstknight Jul 20 '20 at 09:19
  • I have never used YOLO, but the exception gives a hint: "Add operations to the graph before calling run()". Perhaps if you do that, it will work – Mike Driscoll Jul 20 '20 at 13:40
  • Thanks you, @Mike Driscoll. I got it. I try call this method `keras.backend.get_session()` in a new thread and then load yolo model, I don't get the error. – burstknight Jul 28 '20 at 02:58