前提・実現したいこと
yolov3を使って自前データを学習させ、物体検出を行おうと思っています。
自前データを用意し、labelimgでアノテーションを行いました。
その後学習させ、検出結果を出力しようとしたのですが、エラーが出てしまい結果が出てきませんでした。
色々調べたのですが、解決方法が見つからず・・・
原因は恐らく以下のエラー中のこの部分かと思います。
raise ValueError("Shapes %s and %s are incompatible" % (self, other))
ValueError: Shapes (255,) and (42,) are incompatible
発生している問題・エラーメッセージ
Traceback (most recent call last): File "detect_video.py", line 90, in <module> app.run(main) File "C:\ProgramData\Anaconda3\envs\yolov3-tf2-gpu\lib\site-packages\absl\app.py", line 303, in run _run_main(main, args) File "C:\ProgramData\Anaconda3\envs\yolov3-tf2-gpu\lib\site-packages\absl\app.py", line 251, in _run_main sys.exit(main(argv)) File "detect_video.py", line 35, in main yolo.load_weights(FLAGS.weights) File "C:\ProgramData\Anaconda3\envs\yolov3-tf2-gpu\lib\site-packages\tensorflow_core\python\keras\engine\training.py", line 234, in load_weights return super(Model, self).load_weights(filepath, by_name, skip_mismatch) File "C:\ProgramData\Anaconda3\envs\yolov3-tf2-gpu\lib\site-packages\tensorflow_core\python\keras\engine\network.py", line 1193, in load_weights status = self._trackable_saver.restore(filepath) File "C:\ProgramData\Anaconda3\envs\yolov3-tf2-gpu\lib\site-packages\tensorflow_core\python\training\tracking\util.py", line 1283, in restore checkpoint=checkpoint, proto_id=0).restore(self._graph_view.root) File "C:\ProgramData\Anaconda3\envs\yolov3-tf2-gpu\lib\site-packages\tensorflow_core\python\training\tracking\base.py", line 209, in restore restore_ops = trackable._restore_from_checkpoint_position(self) # pylint: disable=protected-access File "C:\ProgramData\Anaconda3\envs\yolov3-tf2-gpu\lib\site-packages\tensorflow_core\python\training\tracking\base.py", line 908, in _restore_from_checkpoint_position tensor_saveables, python_saveables)) File "C:\ProgramData\Anaconda3\envs\yolov3-tf2-gpu\lib\site-packages\tensorflow_core\python\training\tracking\util.py", line 289, in restore_saveables validated_saveables).restore(self.save_path_tensor) File "C:\ProgramData\Anaconda3\envs\yolov3-tf2-gpu\lib\site-packages\tensorflow_core\python\training\saving\functional_saver.py", line 255, in restore restore_ops.update(saver.restore(file_prefix)) File "C:\ProgramData\Anaconda3\envs\yolov3-tf2-gpu\lib\site-packages\tensorflow_core\python\training\saving\functional_saver.py", line 102, in restore restored_tensors, restored_shapes=None) File "C:\ProgramData\Anaconda3\envs\yolov3-tf2-gpu\lib\site-packages\tensorflow_core\python\training\saving\saveable_object_util.py", line 116, in restore self.handle_op, self._var_shape, restored_tensor) File "C:\ProgramData\Anaconda3\envs\yolov3-tf2-gpu\lib\site-packages\tensorflow_core\python\ops\resource_variable_ops.py", line 297, in shape_safe_assign_variable_handle shape.assert_is_compatible_with(value_tensor.shape) File "C:\ProgramData\Anaconda3\envs\yolov3-tf2-gpu\lib\site-packages\tensorflow_core\python\framework\tensor_shape.py", line 1110, in assert_is_compatible_with raise ValueError("Shapes %s and %s are incompatible" % (self, other)) ValueError: Shapes (255,) and (42,) are incompatible WARNING:tensorflow:Unresolved object in checkpoint: (root).optimizer W1120 16:47:36.936927 32388 util.py:144] Unresolved object in checkpoint: (root).optimizer WARNING:tensorflow:Unresolved object in checkpoint: (root).optimizer.iter W1120 16:47:36.936927 32388 util.py:144] Unresolved object in checkpoint: (root).optimizer.iter WARNING:tensorflow:Unresolved object in checkpoint: (root).optimizer.beta_1 W1120 16:47:36.936927 32388 util.py:144] Unresolved object in checkpoint: (root).optimizer.beta_1 WARNING:tensorflow:Unresolved object in checkpoint: (root).optimizer.beta_2 W1120 16:47:36.936927 32388 util.py:144] Unresolved object in checkpoint: (root).optimizer.beta_2 WARNING:tensorflow:Unresolved object in checkpoint: (root).optimizer.decay W1120 16:47:36.936927 32388 util.py:144] Unresolved object in checkpoint: (root).optimizer.decay WARNING:tensorflow:Unresolved object in checkpoint: (root).optimizer.learning_rate W1120 16:47:36.936927 32388 util.py:144] Unresolved object in checkpoint: (root).optimizer.learning_rate WARNING:tensorflow:Unresolved object in checkpoint: (root).optimizer's state 'm' for (root).layer_with_weights-1.layer_with_weights-0.kernel W1120 16:47:36.936927 32388 util.py:144] Unresolved object in checkpoint: (root).optimizer's state 'm' for (root).layer_with_weights-1.layer_with_weights-0.kernel WARNING:tensorflow:Unresolved object in checkpoint: (root).optimizer's state 'm' for (root).layer_with_weights-1.layer_with_weights-1.gamma W1120 16:47:36.936927 32388 util.py:144] Unresolved object in checkpoint: (root).optimizer's state 'm' for (root).layer_with_weights-1.layer_with_weights-1.gamma WARNING:tensorflow:Unresolved object in checkpoint: (root).optimizer's state 'm' for (root).layer_with_weights-1.layer_with_weights-1.beta W1120 16:47:36.936927 32388 util.py:144] Unresolved object in checkpoint: (root).optimizer's state 'm' for (root).layer_with_weights-1.layer_with_weights-1.beta WARNING:tensorflow:Unresolved object in checkpoint: (root).optimizer's state 'm' for (root).layer_with_weights-1.layer_with_weights-2.kernel W1120 16:47:36.936927 32388 util.py:144] Unresolved object in checkpoint: (root).optimizer's state 'm' for (root).layer_with_weights-1.layer_with_weights-2.kernel ・ ・ ・ WARNING:tensorflow:Unresolved object in checkpoint: (root).optimizer's state 'v' for (root).layer_with_weights-6.layer_with_weights-1.beta W1120 16:47:36.952536 32388 util.py:144] Unresolved object in checkpoint: (root).optimizer's state 'v' for (root).layer_with_weights-6.layer_with_weights-1.beta WARNING:tensorflow:Unresolved object in checkpoint: (root).optimizer's state 'v' for (root).layer_with_weights-6.layer_with_weights-2.kernel W1120 16:47:36.952536 32388 util.py:144] Unresolved object in checkpoint: (root).optimizer's state 'v' for (root).layer_with_weights-6.layer_with_weights-2.kernel WARNING:tensorflow:Unresolved object in checkpoint: (root).optimizer's state 'v' for (root).layer_with_weights-6.layer_with_weights-2.bias W1120 16:47:36.952536 32388 util.py:144] Unresolved object in checkpoint: (root).optimizer's state 'v' for (root).layer_with_weights-6.layer_with_weights-2.bias WARNING:tensorflow:A checkpoint was restored (e.g. tf.train.Checkpoint.restore or tf.keras.Model.load_weights) but not all checkpointed values were used. See above for specific issues. Use expect_partial() on the load status object, e.g. tf.train.Checkpoint.restore(...).expect_partial(), to silence these warnings, or use assert_consumed() to make the check explicit. See https://www.tensorflow.org/guide/checkpoint#loading_mechanics for details. W1120 16:47:36.952536 32388 util.py:152] A checkpoint was restored (e.g. tf.train.Checkpoint.restore or tf.keras.Model.load_weights) but not all checkpointed values were used. See above for specific issues. Use expect_partial() on the load status object, e.g. tf.train.Checkpoint.restore(...).expect_partial(), to silence these warnings, or use assert_consumed() to make the check explicit. See https://www.tensorflow.org/guide/checkpoint#loading_mechanics for details.
該当のソースコード
元となるソースコードは以下から落としてきました。
https://github.com/zzh8829/yolov3-tf2
試したこと
自前データを用意し、アノテーション
以下コマンドでtfrecordファイルを作成(trainとval)
python tools/voc2012.py --data_dir ./VOCdevkit/VOC2012 --split train --output_file ./data/voc2012_train_traffic.tfrecord --classes ./data/traffic_voc2012.names
python tools/voc2012.py --data_dir ./VOCdevkit/VOC2012 --split val --output_file ./data/voc2012_val_traffic.tfrecord --classes ./data/traffic_voc2012.names
以下コマンドでモデルの学習(クラスが9つのモデルを作ろうとしています)
python train.py --dataset ./data/voc2012_train_traffic.tfrecord --val_dataset ./data/voc2012_val_traffic.tfrecord --classes ./data/traffic_voc2012.names --num_classes 9 --mode fit --transfer darknet --batch_size 2 --epochs 5 --weights ./checkpoints/yolov3.tf --weights_num_classes 80
学習したモデルを使って物体検出(学習したデータがyolov3_train_5.tf)(ここでエラー発生)
python detect_video.py --video NNF_201103-120904.AVI --classes ./data/traffic_voc2012.names --weights ./checkpoints/yolov3_train_5.tf num_classes 80 --output ./output.avi
補足情報(FW/ツールのバージョンなど)
pythonは3.7を使用し、モデルはTensorflowで使用可能なyolov3です。
また、環境はAnacondaを使用していて、以下のサイトを参考に進めていました。
https://rightcode.co.jp/blog/information-technology/learn-yolov3-image-windows10-environment-construction
https://rightcode.co.jp/blog/information-technology/learn-yolov3-image-windows10-object-detection
https://qiita.com/plseal/items/f493c67b2e810f2f876e
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。