ssd_detected.cpp代码 head.h代码

ssd_detection.cpp代码

#include "head.h"
#include <caffe/caffe.hpp>
#ifdef USE_OPENCV
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#endif  // USE_OPENCV
#include <algorithm>
#include <iomanip>
#include <iosfwd>
#include <memory>
#include <string>
#include <utility>
#include <vector>

#ifdef USE_OPENCV
using namespace caffe;  // NOLINT(build/namespaces)

class Detector {
public:
    Detector(const string& model_file,
        const string& weights_file,
        const string& mean_file,
        const string& mean_value);

    std::vector<vector<float> > Detect(const cv::Mat& img);

private:
    void SetMean(const string& mean_file, const string& mean_value);

    void WrapInputLayer(std::vector<cv::Mat>* input_channels);

    void Preprocess(const cv::Mat& img,
        std::vector<cv::Mat>* input_channels);

private:
    shared_ptr<Net<float> > net_;
    cv::Size input_geometry_;
    int num_channels_;
    cv::Mat mean_;
};

Detector::Detector(const string& model_file,
    const string& weights_file,
    const string& mean_file,
    const string& mean_value) {
#ifdef CPU_ONLY
    Caffe::set_mode(Caffe::CPU);
#else
    Caffe::set_mode(Caffe::GPU);
#endif

    /* Load the network. */
    net_.reset(new Net<float>(model_file, TEST));
    net_->CopyTrainedLayersFrom(weights_file);

    CHECK_EQ(net_->num_inputs(), 1) << "Network should have exactly one input.";
    CHECK_EQ(net_->num_outputs(), 1) << "Network should have exactly one output.";

    Blob<float>* input_layer = net_->input_blobs()[0];
    num_channels_ = input_layer->channels();
    CHECK(num_channels_ == 3 || num_channels_ == 1)
        << "Input layer should have 1 or 3 channels.";
    input_geometry_ = cv::Size(input_layer->width(), input_layer->height());

    /* Load the binaryproto mean file. */
    SetMean(mean_file, mean_value);
}

std::vector<vector<float> > Detector::Detect(const cv::Mat& img) {
    Blob<float>* input_layer = net_->input_blobs()[0];
    input_layer->Reshape(1, num_channels_,
        input_geometry_.height, input_geometry_.width);
    /* Forward dimension change to all layers. */
    net_->Reshape();

    std::vector<cv::Mat> input_channels;
    WrapInputLayer(&input_channels);

    Preprocess(img, &input_channels);

    net_->Forward();

    /* Copy the output layer to a std::vector */
    Blob<float>* result_blob = net_->output_blobs()[0];
    const float* result = result_blob->cpu_data();
    const int num_det = result_blob->height();
    vector<vector<float> > detections;
    for (int k = 0; k < num_det; ++k) {
        if (result[0] == -1) {
            // Skip invalid detection.
            result += 7;
            continue;
        }
        vector<float> detection(result, result + 7);
        detections.push_back(detection);
        result += 7;
    }
    return detections;
}

/* Load the mean file in binaryproto format. */
void Detector::SetMean(const string& mean_file, const string& mean_value) {
    cv::Scalar channel_mean;
    if (!mean_file.empty()) {
        CHECK(mean_value.empty()) <<
            "Cannot specify mean_file and mean_value at the same time";
        BlobProto blob_proto;
        ReadProtoFromBinaryFileOrDie(mean_file.c_str(), &blob_proto);

        /* Convert from BlobProto to Blob<float> */
        Blob<float> mean_blob;
        mean_blob.FromProto(blob_proto);
        CHECK_EQ(mean_blob.channels(), num_channels_)
            << "Number of channels of mean file doesn't match input layer.";

        /* The format of the mean file is planar 32-bit float BGR or grayscale. */
        std::vector<cv::Mat> channels;
        float* data = mean_blob.mutable_cpu_data();
        for (int i = 0; i < num_channels_; ++i) {
            /* Extract an individual channel. */
            cv::Mat channel(mean_blob.height(), mean_blob.width(), CV_32FC1, data);
            channels.push_back(channel);
            data += mean_blob.height() * mean_blob.width();
        }

        /* Merge the separate channels into a single image. */
        cv::Mat mean;
        cv::merge(channels, mean);

        /* Compute the global mean pixel value and create a mean image
        * filled with this value. */
        channel_mean = cv::mean(mean);
        mean_ = cv::Mat(input_geometry_, mean.type(), channel_mean);
    }
    if (!mean_value.empty()) {
        CHECK(mean_file.empty()) <<
            "Cannot specify mean_file and mean_value at the same time";
        stringstream ss(mean_value);
        vector<float> values;
        string item;
        while (getline(ss, item, ',')) {
            float value = std::atof(item.c_str());
            values.push_back(value);
        }
        CHECK(values.size() == 1 || values.size() == num_channels_) <<
            "Specify either 1 mean_value or as many as channels: " << num_channels_;

        std::vector<cv::Mat> channels;
        for (int i = 0; i < num_channels_; ++i) {
            /* Extract an individual channel. */
            cv::Mat channel(input_geometry_.height, input_geometry_.width, CV_32FC1,
                cv::Scalar(values[i]));
            channels.push_back(channel);
        }
        cv::merge(channels, mean_);
    }
}

void Detector::WrapInputLayer(std::vector<cv::Mat>* input_channels) {
    Blob<float>* input_layer = net_->input_blobs()[0];

    int width = input_layer->width();
    int height = input_layer->height();
    float* input_data = input_layer->mutable_cpu_data();
    for (int i = 0; i < input_layer->channels(); ++i)
    {
        cv::Mat channel(height, width, CV_32FC1, input_data);
        input_channels->push_back(channel);
        input_data += width * height;
    }
}

void Detector::Preprocess(const cv::Mat& img,
    std::vector<cv::Mat>* input_channels) {
    /* Convert the input image to the input image format of the network. */
    cv::Mat sample;
    if (img.channels() == 3 && num_channels_ == 1)
        cv::cvtColor(img, sample, cv::COLOR_BGR2GRAY);
    else if (img.channels() == 4 && num_channels_ == 1)
        cv::cvtColor(img, sample, cv::COLOR_BGRA2GRAY);
    else if (img.channels() == 4 && num_channels_ == 3)
        cv::cvtColor(img, sample, cv::COLOR_BGRA2BGR);
    else if (img.channels() == 1 && num_channels_ == 3)
        cv::cvtColor(img, sample, cv::COLOR_GRAY2BGR);
    else
        sample = img;

    cv::Mat sample_resized;
    if (sample.size() != input_geometry_)
        cv::resize(sample, sample_resized, input_geometry_);
    else
        sample_resized = sample;

    cv::Mat sample_float;
    if (num_channels_ == 3)
        sample_resized.convertTo(sample_float, CV_32FC3);
    else
        sample_resized.convertTo(sample_float, CV_32FC1);

    cv::Mat sample_normalized;
    cv::subtract(sample_float, mean_, sample_normalized);

    /* This operation will write the separate BGR planes directly to the
    * input layer of the network because it is wrapped by the cv::Mat
    * objects in input_channels. */
    cv::split(sample_normalized, *input_channels);

    CHECK(reinterpret_cast<float*>(input_channels->at(0).data)
        == net_->input_blobs()[0]->cpu_data())
        << "Input channels are not wrapping the input layer of the network.";
}

DEFINE_string(mean_file, "",
    "The mean file used to subtract from the input image.");
DEFINE_string(mean_value, "104,117,123",
    "If specified, can be one value or can be same as image channels"
    " - would subtract from the corresponding channel). Separated by ','."
    "Either mean_file or mean_value should be provided, not both.");
DEFINE_string(file_type, "image",
    "The file type in the list_file. Currently support image and video.");
DEFINE_string(out_file, "",
    "If provided, store the detection results in the out_file.");
DEFINE_double(confidence_threshold, 0.01,
    "Only store detections with score higher than the threshold.");


//string num2label(int num)
//{
//  string labels[25]{"", "airplane", "bicycle", "bird", "boat", "bottle", "bus", "car",
//      "cat", "chair", "cow", "table", "dog", "horse", "motobike",
//      "person", "pottedplant", "sheep", "sofa", "train", "tvmonitor"};
//  return labels[num];
//}

string num2label(int num)
{
    string labels[2]{"", "car"};

    return labels[num];
}
cv::Point pt1;
cv::Point pt2;

/*********************************************************//*********************************************************/
/*********************************************************//*********************************************************/

int main(int argc, char** argv)
{
    ::google::InitGoogleLogging(argv[0]);
    // Print output to stderr (while still logging)
    FLAGS_alsologtostderr = 1;

#ifndef GFLAGS_GFLAGS_H_
    namespace gflags = google;
#endif


    const string& model_file("deploy.prototxt");  //prototxt文件
    const string& weights_file("VGG_VOC0712_SSD_300x300_iter_15000.caffemodel");;  //caffemodel文件
    const string& mean_file = FLAGS_mean_file;
    const string& mean_value = FLAGS_mean_value;
    const float confidence_threshold = FLAGS_confidence_threshold;

    // 加载网络
    Detector detector(model_file, weights_file, mean_file, mean_value);


    //////////
    cvNamedWindow("SSD", 0);
    cv::VideoCapture cap("2.mp4");
    if (!cap.isOpened())
    {
        LOG(FATAL) << "Failed to open video: ";
    }
    cv::Mat img;
    int frame_count = 0;
    while (true)
    {
        bool success = cap.read(img);
        if (!success)
        {
            LOG(INFO) << "Process " << frame_count << " frames from ";
            break;
        }
        CHECK(!img.empty()) << "Error when read frame";

        std::vector<vector<float> > detections = detector.Detect(img);

        /* Print the detection results. */
        for (int i = 0; i < detections.size(); ++i)
        {
            const vector<float>& d = detections[i];
            // Detection format: d[image_id, label, score, xmin, ymin, xmax, ymax].
            CHECK_EQ(d.size(), 7);
            const float score = d[2];

            if (score >= 0.6)  //【置信度】
            {
                //pt1.x = d[3] * img.cols;
                //pt1.y = d[4] * img.rows;
                //pt2.x = d[5] * img.cols;
                //pt2.y = d[6] * img.rows;
                //rectangle(img, pt1, pt2, cv::Scalar(0, 0, 255), 3, 8, 0);
                int posx = static_cast<int>(d[3] * img.cols);
                int posy = static_cast<int>(d[4] * img.rows);
                int posw = static_cast<int>(d[5] * img.cols) - posx;
                int posh = static_cast<int>(d[6] * img.rows) - posy;
                cv::Rect pos(posx, posy, posw, posh);
                cv::rectangle(img, pos, cv::Scalar(0, static_cast<int>(d[1]) / 21.0 * 255, 255));  //细、橙色框

                char buffer[50];
                _gcvt(score, 2, buffer);
                std::string words = std::string(buffer);
                words = num2label(static_cast<int>(d[1])) + " : " + words;
                cv::putText(img, words, cv::Point(posx, posy), CV_FONT_HERSHEY_COMPLEX, 0.4, cv::Scalar(0, static_cast<int>(d[1]) / 21.0 * 255, 255));
            }
        }
        cv::imshow("SSD", img);
        cv::waitKey(24);

        ++frame_count;
    }
    //////////


    if (cap.isOpened()) //释放相机cap
    {
        cap.release();
    }



    return 0;
}
#else
int main(int argc, char** argv) {
    LOG(FATAL) << "This example requires OpenCV; compile with USE_OPENCV.";
}
#endif  // USE_OPENCV

head.h代码

#ifndef CAFFE_REG_H  
#define CAFFE_REG_H  
#include "caffe/common.hpp"    
#include "caffe/layers/input_layer.hpp"    
#include "caffe/layers/inner_product_layer.hpp"    
#include "caffe/layers/dropout_layer.hpp"    
#include "caffe/layers/conv_layer.hpp"    
#include "caffe/layers/relu_layer.hpp"    
#include "caffe/layers/pooling_layer.hpp"    
#include "caffe/layers/lrn_layer.hpp"    
#include "caffe/layers/softmax_layer.hpp"    
#include "caffe/layers/normalize_layer.hpp"  
#include "caffe/layers/permute_layer.hpp"  
#include "caffe/layers/flatten_layer.hpp"  
#include "caffe/layers/prior_box_layer.hpp"  
#include "caffe/layers/concat_layer.hpp"  
#include "caffe/layers/reshape_layer.hpp"  
#include "caffe/layers/softmax_layer.hpp"  
#include "caffe/layers/detection_output_layer.hpp"  
namespace caffe
{
    extern INSTANTIATE_CLASS(InputLayer);
    extern INSTANTIATE_CLASS(ConvolutionLayer);
    REGISTER_LAYER_CLASS(Convolution);
    extern INSTANTIATE_CLASS(InnerProductLayer);
    extern INSTANTIATE_CLASS(DropoutLayer);
    extern INSTANTIATE_CLASS(ReLULayer);
    REGISTER_LAYER_CLASS(ReLU);
    extern INSTANTIATE_CLASS(PoolingLayer);
    REGISTER_LAYER_CLASS(Pooling);
    extern INSTANTIATE_CLASS(LRNLayer);
    //REGISTER_LAYER_CLASS(LRN);  
    extern INSTANTIATE_CLASS(SoftmaxLayer);
    //REGISTER_LAYER_CLASS(Softmax);  
    extern INSTANTIATE_CLASS(NormalizeLayer);
    //REGISTER_LAYER_CLASS(Normalize);  
    extern INSTANTIATE_CLASS(PermuteLayer);
    //REGISTER_LAYER_CLASS(Permute);  
    extern INSTANTIATE_CLASS(FlattenLayer);
    extern INSTANTIATE_CLASS(PriorBoxLayer);
    extern INSTANTIATE_CLASS(ConcatLayer);
    extern INSTANTIATE_CLASS(ReshapeLayer);
    extern INSTANTIATE_CLASS(SoftmaxLayer);
    REGISTER_LAYER_CLASS(Softmax);
    extern INSTANTIATE_CLASS(DetectionOutputLayer);
}
#endif  
02:32:46.785: rfc_lte.cpp:694 Select LTE TX band enum 54 on device 0 02:32:46.785: rfc_lte.cpp:708 tx_band_config: Setting to defaults, TX band enum 54 on device 0 02:32:46.785: rfdevice_pa_common.cpp:942 PA does not have exclusive ON register, using low PA gain and default ICQ to turn ON PA 02:32:46.785: rfdevice_pa_common.cpp:758 PA Set TXAGC failed in set current bias 02:32:46.785: rflte_dm_tx.c:3133 Error getting set_pa_txagc from device 02:32:46.785: rflte_dm_common.c:544 NO script is populated for rflm event buffer, num_trans: 0, resource_script_rffe_ptr 0x86A86DB0 02:32:46.785: rfdevice_pa_common.cpp:758 PA Set TXAGC failed in set current bias 02:32:46.785: rflte_dm_tx.c:3133 Error getting set_pa_txagc from device 02:32:46.785: rflte_dm_common.c:544 NO script is populated for rflm event buffer, num_trans: 0, resource_script_rffe_ptr 0x86A86DB0 02:32:46.785: rfdevice_pa_common.cpp:758 PA Set TXAGC failed in set current bias 02:32:46.785: rflte_dm_tx.c:3133 Error getting set_pa_txagc from device 02:32:46.785: rflte_dm_common.c:544 NO script is populated for rflm event buffer, num_trans: 0, resource_script_rffe_ptr 0x86A86DB0 02:32:46.785: rfdevice_pa_common.cpp:758 PA Set TXAGC failed in set current bias 02:32:46.785: rflte_dm_tx.c:3133 Error getting set_pa_txagc from device 02:32:46.785: rflte_dm_common.c:544 NO script is populated for rflm event buffer, num_trans: 0, resource_script_rffe_ptr 0x86A86DB0 02:32:46.785: rfdevice_pa_common.cpp:942 PA does not have exclusive ON register, using low PA gain and default ICQ to turn ON PA 02:32:46.785: rfdevice_pa_common.cpp:758 PA Set TXAGC failed in set current bias 02:32:46.785: rflte_dm_tx.c:3176 Error getting pa gain range data from device 02:32:46.901: rflte_dm_tx.c:3234 Assertion TRUE == rflte_dm_tx_pa_device_not_detected failed
最新发布
07-26
<think>我们正在分析LTE设备中PA(功率放大器)配置失败的问题,具体错误是“PA Set TXAGC失败”和断言错误“Assertion TRUE == rflte_dm_tx_pa_device_not_detected”。 根据引用[2],在配置PA时,会调用set_pa_on_off或config函数,这些函数会获取PA的配置参数(如寄存器地址、数据等)。如果设备未检测到PA,可能会导致断言失败。 引用[2]中的代码片段显示,当请求为RFDEVICE_PA_ON_DATA时,会设置PA的寄存器地址和数据。如果PA设备没有被正确检测或初始化,则可能导致设置失败。 可能的原因和解决方案: 1. PA设备未正确检测:检查硬件连接和PA设备是否被正确识别。引用[1]中描述了PHY设备的属性,包括制造商ID、产品ID等,确保这些与硬件匹配。 2. 配置参数错误:检查PA的配置参数(如寄存器设置)是否正确。引用[2]中使用了特定的寄存器数组(rfdevice_pa_sky_77629_51_pa_on_regs和rfdevice_pa_sky_77629_51_pa_on_data),确保这些数据与当前使用的PA型号匹配。 3. PA初始化问题:引用[1]中有一个字段“INIT”被设置为FALSE,这可能导致设备未初始化。需要确保在配置前正确初始化PA设备。 4. 功率控制设置:引用[3]提到了ETSI功率控制,如果功率控制设置不当,也可能导致PA配置问题。可以尝试调整功率控制设置。 步骤: 1. 确认PA设备在硬件上连接正确,并且被软件正确识别(检查设备树或相关配置)。 2. 检查代码中PA的配置数据(寄存器地址、数据)是否与当前使用的PA型号匹配。如果不匹配,需要更新为正确的配置数据。 3. 确保在配置PA之前,已经调用了初始化函数(将INIT字段设置为TRUE)。 4. 检查功率控制设置,确保符合区域要求(如ETSI)。 如果问题仍然存在,可能需要查看更详细的日志以确定具体失败点。 相关问题: 1. 如何调试LTE设备中的PA初始化问题? 2. 如何验证PA的寄存器配置是否正确? 3. 在LTE设备中,功率控制设置对PA工作有什么影响?</think>### 解决LTE设备中PA配置失败和断言错误的分析 #### 问题分析 1. **PA Set TXAGC失败** 当调用`set_pa_txagc`时,设备无法正确配置PA的发射增益(TXAGC)。引用[2]显示,此过程涉及获取PA寄存器配置数据: ```cpp pa_data_ptr->settings_data_get(&pa_params_cfg, &pa_reg_ag); // 获取PA配置参数 ``` 失败可能原因: - PA寄存器配置数据与硬件不匹配(如寄存器地址/值错误) - PA设备未被正确检测或初始化(见断言错误) 2. **断言错误 `TRUE == rflte_dm_tx_pa_device_not_detected`** 此断言表明软件未检测到PA硬件设备。引用[1]描述了PA设备的检测逻辑: ```cpp { 0x217, /* PHY_DEVICE_MANUFACTURER_ID */ 0xCA, /* PHY_DEVICE_PRODUCT_ID */ ... // 其他识别参数 } ``` 失败可能原因: - 硬件连接异常(如RFFE总线通信故障) - 设备ID(制造商ID/产品ID)配置错误 - PA未在设备树中正确注册 --- #### 解决方案 1. **验证PA硬件检测** - 检查RFFE总线通信:使用示波器确认SCLK/SDATA信号是否正常(引用[1]中`{4,0}`表示总线配置) - 核对设备ID:确保代码中配置的制造商ID(0x217)和产品ID(0xCA)与实际硬件一致 - 确认设备初始化:引用[1]中`INIT: FALSE`表明需调用初始化函数,添加: ```cpp rfdevice_pa_init(pa_device); // 显式初始化PA设备 ``` 2. **修复PA寄存器配置** 引用[2]显示配置依赖预定义寄存器数组: ```cpp settings->addr = &rfdevice_pa_sky_77629_51_pa_on_regs[0]; // 寄存器地址 settings->data = &rfdevice_pa_sky_77629_51_pa_on_data[cfg->port][0]; // 寄存器值 ``` 需: - 确认当前PA型号(如SKY77629)与数组匹配 - 检查`cfg->port`索引是否有效(避免越界) 3. **添加容错机制** 在断言前增加设备检测重试逻辑: ```cpp for (int retry = 0; retry < 3; retry++) { if (rflte_dm_tx_pa_device_detected()) break; // 检测PA设备 sleep_ms(10); } ASSERT(TRUE == rflte_dm_tx_pa_device_detected); // 重试后断言 ``` 4. **功率控制兼容性** 引用[3]的ETSI功率控制可能影响PA使能: ```bash iwpriv wlan0 set_mib disable_txpwrlmt=0 # 启用功率限制 ``` 确保LTE功率配置与区域规范(如ETSI/FCC)兼容,避免软件强制关闭PA。 --- #### 验证步骤 1. 使用RFFE协议分析仪捕获总线通信,确认PA响应 2. 在`settings_data_get()`后添加日志打印寄存器配置: ```cpp LOG("PA Reg: addr=0x%X, data=0x%X", *settings->addr, *settings->data); ``` 3. 若问题持续,检查硬件原理图确认: - PA的USID配置是否匹配引用[1]中`PHY_DEVICE_ASSIGNED_USID=0x1` - 供电电压是否稳定(典型值3.3V±5%) ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值