caffe模型训练个人出错集锦

5、想把yolov3的模型转换为caffe

使用工具:pytorch-caffe-darknet-convert

注意事项:

caffe中必须已经添加了

upsample_layer.cpp

upsample_layer.cu

upsample_layer.hpp

message UpsampleParameter{
  optional int32 scale = 1 [default = 1];
}

然后使用yolov3_darknet2caffe.py

python yolov3_darknet2caffe.py yolov3.cfg yolov3.weights yolov3.prototxt yolov3.caffemodel

error

ValueError: need more than 1 value to unpack

出错不能转换,排查错误

Training应该注释掉,正确应该是

6.多标签分类 0 1 0 1 0 0 0 0 255 255 255

没有加入ignore_label,导致loos为nan和loss超级大

layer {
  name: "cross_entropy"
  type: "SigmoidCrossEntropyLoss"
  bottom: "pedestrian-conv1000"
  bottom: "label"
  top: "cross_entropy"
  loss_param {
    ignore_label: 255
  }
}
template <typename Dtype>
void SigmoidCrossEntropyLossLayer<Dtype>::Forward_cpu(
    const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top) {
  // The forward pass computes the sigmoid outputs.
  sigmoid_bottom_vec_[0] = bottom[0];
  sigmoid_layer_->Forward(sigmoid_bottom_vec_, sigmoid_top_vec_);
  // Compute the loss (negative log likelihood)
  // Stable version of loss computation from input data
  const Dtype* input_data = bottom[0]->cpu_data();
  const Dtype* target = bottom[1]->cpu_data();
  int valid_count = 0;
  Dtype loss = 0;
  for (int i = 0; i < bottom[0]->count(); ++i) {
    const int target_value = static_cast<int>(target[i]);
    if (has_ignore_label_ && target_value == ignore_label_) {
      continue;
    }
    loss -= input_data[i] * (target[i] - (input_data[i] >= 0)) -
        log(1 + exp(input_data[i] - 2 * input_data[i] * (input_data[i] >= 0)));
    ++valid_count;
  }
  normalizer_ = get_normalizer(normalization_, valid_count);
  top[0]->mutable_cpu_data()[0] = loss / normalizer_;
}
template <typename Dtype>
void SigmoidCrossEntropyLossLayer<Dtype>::Backward_cpu(
    const vector<Blob<Dtype>*>& top, const vector<bool>& propagate_down,
    const vector<Blob<Dtype>*>& bottom) {
  if (propagate_down[1]) {
    LOG(FATAL) << this->type()
               << " Layer cannot backpropagate to label inputs.";
  }
  if (propagate_down[0]) {
    // First, compute the diff
    const int count = bottom[0]->count();
    const Dtype* sigmoid_output_data = sigmoid_output_->cpu_data();
    const Dtype* target = bottom[1]->cpu_data();
    Dtype* bottom_diff = bottom[0]->mutable_cpu_diff();
    caffe_sub(count, sigmoid_output_data, target, bottom_diff);
    // Zero out gradient of ignored targets.
    if (has_ignore_label_) {
      for (int i = 0; i < count; ++i) {
        const int target_value = static_cast<int>(target[i]);
        if (target_value == ignore_label_) {
          bottom_diff[i] = 0;
        }
      }
    }
    // Scale down gradient
    Dtype loss_weight = top[0]->cpu_diff()[0] / normalizer_;
    caffe_scal(count, loss_weight, bottom_diff);
  }
}

7.预训练模型尽量加上,会快速降低loss

如果是目标检测的预训练模型,也可以用在目标分类上

8.可以尝试对网络剪枝

比如yolov3-tiny通道数目减半,只要数据可以,不会影响网络整体的效果

在下载已经训练好的caffe模型之前,首先需要确定模型的来源和可靠性。可以通过官方网站、论坛或专门的模型库来获取可信赖的模型。接下来,按照以下步骤来下载模型: 1. 打开模型下载链接或网站,查找适合你任务的模型。可以根据模型的名称、用途、数据集等信息筛选。 2. 确认模型的格式。caffe模型通常以`.caffemodel`的文件格式保存。还有可能需要下载对应的网络结构描述文件(`.prototxt`)。 3. 点击下载按钮或链接,保存模型文件到本地。 4. 下载完成后,检查模型文件的完整性。可以使用文件哈希值进行校验,确保文件未被损坏或篡改。 5. 解压模型文件(如果需要)。一般来说,`.caffemodel`文件不需要解压,但有时候可能还会附带其他辅助文件或文件夹,需要进行解压操作。 6. 准备使用已下载的caffe模型。在使用前,需要确保已正确配置caffe环境,包括安装相关的依赖库和配置路径等。可以参考caffe官方文档或相关教程来进行配置。 7. 将模型加载caffe中。可以使用caffe提供的API来载入模型,之后就可以使用模型进行推理或其他任务。 需要注意的是,模型的下载过程可能因模型大小、网络速度等因素而耗时较长。此外,在使用已训练好的caffe模型时,还需要根据具体任务进行适当的微调或调整,以获得理想的结果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值