首页 > 其他分享 >Yolov3模型转caffe模型

Yolov3模型转caffe模型

时间:2022-09-26 08:45:23浏览次数:79  
标签:layers layer Yolov3 ++ 模型 darknet2caffe caffe optional

Yolov3模型转caffe模型

  • 前提下载docker和nvidia-docker百度去下载即可
  • 基础镜像拉取
sudo docker pull bvlc/caffe:gpu
  • 配置/etc/docker/daemon.json
{
    "registry-mirrors": ["你的加速仓库地址"],
    "runtimes": {
        "nvidia": {
            "path": "/usr/bin/nvidia-container-runtime",
            "runtimeArgs": []
         }	
    }
}
  • 创建容器
docker run --runtime=nvidia --name caffe -i -t bvlc/caffe /bin/bash
  • 镜像原有版本为cuda8,这里我下载11.4。cuda版本过低可能会报错:nvcc fatal : Unsupported gpu architecture compute_86
wget https://developer.download.nvidia.com/compute/cuda/11.4.2/local_installers/cuda_11.4.2_470.57.02_linux.run

sudo sh cuda_11.4.2_470.57.02_linux.run

注意下载时候取消勾选Driver

  • 进入容器,git下载代码
git clone https://github.com/ChenYingpeng/darknet2caffe.git
  • 下载一波依赖
apt-get install -y libglew-dev g++
  • 因为要转yolov3为caffe需要做几处调整
将 darknet2caffe/caffe_layers/mish_layer 下的 mish_layer.hpp 文件 
将 darknet2caffe/caffe_layers/upsample_layer/ 下的 upsample_layer.hpp 文件 
	拷贝到容器的路径:/opt/caffe/include/caffe/layers

将 darknet2caffe/caffe_layers/mish_layer 下的 mish_layer.cpp、mish_layer.cu 文件
将 darknet2caffe/caffe_layers/upsample_layer 下的 upsample_layer.cpp、upsample_layer.cu 文件
    拷贝到容器的路径:/opt/caffe/src/caffe/layers/  下。

将 darknet2caffe/caffe_layers/pooling_layer 下的 pooling_layer.cpp 文件
	拷贝到容器的路径:/opt/caffe/src/caffe/layers/  下。
  • 然后,打开容器内的 caffe 文件:/opt/caffe/src/caffe/proto/caffe.proto。按照如下说明修改相应字段的程序。
// LayerParameter next available layer-specific ID: 147 (last added: recurrent_param)
message LayerParameter {
  optional TileParameter tile_param = 138;
  optional VideoDataParameter video_data_param = 207;
  optional WindowDataParameter window_data_param = 129;
++optional UpsampleParameter upsample_param = 149; //added by chen for Yolov3, make sure this id 149 not the same as before.
++optional MishParameter mish_param = 150; //added by chen for yolov4,make sure this id 150 not the same as before.
}

// added by chen for YoloV3
++message UpsampleParameter{
++  optional int32 scale = 1 [default = 1];
++}

// Message that stores parameters used by MishLayer
++message MishParameter {
++  enum Engine {
++    DEFAULT = 0;
++    CAFFE = 1;
++    CUDNN = 2;
++  }
++  optional Engine engine = 2 [default = DEFAULT];
++}

其中,++ 表示该行是增加的内容。

  • 编译
make clean
make all -j8
make pycaffe -j8
  • /workspace/darknet2caffe模型转换
python darknet2caffe.py ./yolov3.cfg ./yolov3.weights ./yolov3.prototxt ./yolov3.caffemodel
  • 参考

https://developer.aliyun.com/article/840496

https://www.cnblogs.com/wind-chaser/p/14391497.html

标签:layers,layer,Yolov3,++,模型,darknet2caffe,caffe,optional
From: https://www.cnblogs.com/xujunkai/p/16729651.html

相关文章