如果您使用自定义锚点进行训练,如何将 YOLOv4 暗网权重转换为 Tensorflow 格式?

How to convert YOLOv4 Darknet Weights to Tensorflow format if you trained with custom anchors?

主要问题:

我应该对 repo 的源代码做哪些更改才能成功将我的 YOLOv4 暗网权重(使用自定义锚点)转换为 Tensorflow 格式?

背景:

我使用 this repo 将我的 YOLOv4 暗网权重转换为 Tensorflow 格式。

我使用自定义锚点(9个锚点)在自定义数据集上训练了YOLOv4,但是我每个[yolo]使用的锚点数量]层分别为4、3、2。默认情况下,YOLOv4 每个 [yolo] 层使用 3 个锚点。

主要问题:

我使用的 repo 的编码方式只考虑默认锚点,其中有 3 anchors each [yolo] layer.

我试图解决主要问题的方法:

python save_model.py --weights data/yolov4-512.weights --output ./checkpoints/yolov4-512 --input_size 512 --model yolov4

2021-03-19 15:05:03.694379: W tensorflow/core/common_runtime/bfc_allocator.cc:312] Garbage collection: deallocate free memory regions (i.e., allocations) so that we can re-allocate a larger region to avoid OOM due to memory fragmentation. If you see this message frequently, you are running near the threshold of the available device memory and re-allocation may incur great performance overhead. You may try smaller batch sizes to observe the performance impact. Set TF_ENABLE_GPU_GARBAGE_COLLECTION=false if you'd like to disable this feature.
    Traceback (most recent call last):
      File "detect.py", line 90, in <module>
        app.run(main)
      File "C:\Python37\lib\site-packages\absl\app.py", line 303, in run
        _run_main(main, args)
      File "C:\Python37\lib\site-packages\absl\app.py", line 251, in _run_main
        sys.exit(main(argv))
      File "detect.py", line 66, in main
        pred_bbox = infer(batch_data)
      File "C:\Python37\lib\site-packages\tensorflow\python\eager\function.py", line 1655, in __call__
        return self._call_impl(args, kwargs)
      File "C:\Python37\lib\site-packages\tensorflow\python\eager\function.py", line 1673, in _call_impl
        return self._call_with_flat_signature(args, kwargs, cancellation_manager)
      File "C:\Python37\lib\site-packages\tensorflow\python\eager\function.py", line 1722, in _call_with_flat_signature
        return self._call_flat(args, self.captured_inputs, cancellation_manager)
      File "C:\Python37\lib\site-packages\tensorflow\python\saved_model\load.py", line 106, in _call_flat
        cancellation_manager)
      File "C:\Python37\lib\site-packages\tensorflow\python\eager\function.py", line 1924, in _call_flat
        ctx, args, cancellation_manager=cancellation_manager))
      File "C:\Python37\lib\site-packages\tensorflow\python\eager\function.py", line 550, in call
        ctx=ctx)
      File "C:\Python37\lib\site-packages\tensorflow\python\eager\execute.py", line 60, in quick_execute
        inputs, attrs, num_outputs)
    tensorflow.python.framework.errors_impl.InvalidArgumentError:  Input to reshape is a tensor with 98304 values, but the requested shape has 73728
             [[{{node StatefulPartitionedCall/functional_1/tf_op_layer_Reshape/Reshape}}]] [Op:__inference_signature_wrapper_5589]
    
    Function call stack:
    signature_wrapper

我发布了一个关于 YoloV4 (CSP) 转换的 答案。您试过看看是否有效吗?

如果可行,您可以尝试在 notebook 的 convert.py 命令中使用您自己的配置文件和权重,看看是否可行