zoukankan      html  css  js  c++  java
  • caffe: fuck compile error again : error: a value of type "const float *" cannot be used to initialize an entity of type "float *"

    wangxiao@wangxiao-GTX980:~/Downloads/caffe-master$ make -j8
    find: `wangxiao/bvlc_alexnet/spl': No such file or directory
    find: `caffemodel': No such file or directory
    find: `wangxiao/bvlc_alexnet/0.77': No such file or directory
    find: `caffemodel': No such file or directory
    NVCC src/caffe/layers/euclidean_loss_layer.cu
    src/caffe/layers/euclidean_loss_layer.cu(41): error: a value of type "const float *" cannot be used to initialize an entity of type "float *"
              detected during instantiation of "void caffe::EuclideanLossLayer<Dtype>::Backward_gpu(const std::vector<caffe::Blob<Dtype> *, std::allocator<caffe::Blob<Dtype> *>> &, const std::vector<__nv_bool, std::allocator<__nv_bool>> &, const std::vector<caffe::Blob<Dtype> *, std::allocator<caffe::Blob<Dtype> *>> &) [with Dtype=float]"
    (140): here

    src/caffe/layers/euclidean_loss_layer.cu(42): error: a value of type "const float *" cannot be used to initialize an entity of type "float *"
              detected during instantiation of "void caffe::EuclideanLossLayer<Dtype>::Backward_gpu(const std::vector<caffe::Blob<Dtype> *, std::allocator<caffe::Blob<Dtype> *>> &, const std::vector<__nv_bool, std::allocator<__nv_bool>> &, const std::vector<caffe::Blob<Dtype> *, std::allocator<caffe::Blob<Dtype> *>> &) [with Dtype=float]"
    (140): here

    src/caffe/layers/euclidean_loss_layer.cu(41): error: a value of type "const double *" cannot be used to initialize an entity of type "double *"
              detected during instantiation of "void caffe::EuclideanLossLayer<Dtype>::Backward_gpu(const std::vector<caffe::Blob<Dtype> *, std::allocator<caffe::Blob<Dtype> *>> &, const std::vector<__nv_bool, std::allocator<__nv_bool>> &, const std::vector<caffe::Blob<Dtype> *, std::allocator<caffe::Blob<Dtype> *>> &) [with Dtype=double]"
    (140): here

    src/caffe/layers/euclidean_loss_layer.cu(42): error: a value of type "const double *" cannot be used to initialize an entity of type "double *"
              detected during instantiation of "void caffe::EuclideanLossLayer<Dtype>::Backward_gpu(const std::vector<caffe::Blob<Dtype> *, std::allocator<caffe::Blob<Dtype> *>> &, const std::vector<__nv_bool, std::allocator<__nv_bool>> &, const std::vector<caffe::Blob<Dtype> *, std::allocator<caffe::Blob<Dtype> *>> &) [with Dtype=double]"
    (140): here

    4 errors detected in the compilation of "/tmp/tmpxft_000007e5_00000000-16_euclidean_loss_layer.compute_50.cpp1.ii".
    make: *** [.build_debug/cuda/src/caffe/layers/euclidean_loss_layer.o] Error 1
    wangxiao@wangxiao-GTX980:~/Downloads/caffe-master$

    ----------------------------------------------------------------------

    ----------------------------------------------------------------------

    原因分析:

    主要是因为,在欧式距离损失函数中,我增添了以下两句话:

           Dtype* diff_cpu_data = bottom[i]->mutable_cpu_diff();
           Dtype* label_data = bottom[1]->cpu_data();    // label data: 0 or 1
           Dtype* predict_data = bottom[0]->cpu_data();  // predict data

    再来看看提示的错误:

    src/caffe/layers/euclidean_loss_layer.cu(41): error: a value of type "const float *" cannot be used to initialize an entity of type "float *"
              detected during instantiation of "void caffe::EuclideanLossLayer<Dtype>::Backward_gpu(const std::vector<caffe::Blob<Dtype> *, std::allocator<caffe::Blob<Dtype> *>> &, const std::vector<__nv_bool, std::allocator<__nv_bool>> &, const std::vector<caffe::Blob<Dtype> *, std::allocator<caffe::Blob<Dtype> *>> &) [with Dtype=float]"
    (140): here

    src/caffe/layers/euclidean_loss_layer.cu(42): error: a value of type "const float *" cannot be used to initialize an entity of type "float *"
              detected during instantiation of "void caffe::EuclideanLossLayer<Dtype>::Backward_gpu(const std::vector<caffe::Blob<Dtype> *, std::allocator<caffe::Blob<Dtype> *>> &, const std::vector<__nv_bool, std::allocator<__nv_bool>> &, const std::vector<caffe::Blob<Dtype> *, std::allocator<caffe::Blob<Dtype> *>> &) [with Dtype=float]"
    (140): here

    肯定是少了 const 约束:

    so , 改为:

    const Dtype* label_data = bottom[1]->cpu_data();    // label data: 0 or 1
    const Dtype* predict_data = bottom[0]->cpu_data();  // predict data

    在编译,就ok啦 ~~

    2. 问题2:

    CXX src/caffe/layers/accuracy_layer.cpp
    src/caffe/layers/accuracy_layer.cpp: In instantiation of ‘void caffe::AccuracyLayer<Dtype>::Forward_cpu(const std::vector<caffe::Blob<Dtype>*>&, const std::vector<caffe::Blob<Dtype>*>&) [with Dtype = float]’:
    src/caffe/layers/accuracy_layer.cpp:286:1:   required from here
    src/caffe/layers/accuracy_layer.cpp:98:21: error: assignment of read-only location ‘*(bottom_data + 84u)’
         bottom_data[21] = 1; bottom_data[22] = 0; bottom_data[23] = 0; bottom_data[24] = 0;
     

    看到错误就应该知道:错误的原因是给只读的变量赋值了。。。

    但是,又想改变那个值,来作为最后求解的结果,怎么办呢? 好吧,那就只好先将该变量存到一个中间变量里面去了,但是,问题又来了,原本const 的变量可以赋值给普通的变量么?

    例如: float a = const float b ? 这样ok么?我觉得不ok,先试试吧。。。

  • 相关阅读:
    服务器连接华为存储配置操作
    ZABBIX 3.0 配置监控NGINX性能【OK】
    使用jvisualvm工具来监控java运行情况
    运行python时提示:ImportError: No module named plyvel ,ImportError No module named irc 解决过程:
    centos7安装ZABBIX 3.0+ 邮件报警【OK】
    给阿里云ECS主机添加IPV6地址
    出现错误日志:The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path
    [Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'localhost' (using password: YES)
    LINUX安全加固操作
    【转】解决virtmanager启动管理器出错:unsupported format character
  • 原文地址:https://www.cnblogs.com/wangxiaocvpr/p/5212115.html
Copyright © 2011-2022 走看看