Skip to content

Commit

Permalink
Add evaluate function
Browse files Browse the repository at this point in the history
  • Loading branch information
eric612 committed Mar 12, 2019
1 parent 78f8071 commit 02c455d
Show file tree
Hide file tree
Showing 11 changed files with 655 additions and 33 deletions.
2 changes: 1 addition & 1 deletion examples/yolo/yolo_detect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ void MatMul(cv::Mat img1, cv::Mat img2,int idx=0)
int img_index1 = 0;
int img_index2 = 0;
for (j = 0; j < width; j++) {
if(ptr2[img_index2]>20) {
if(ptr2[img_index2]>120) {
ptr1[img_index1+idx] = 127 + ptr1[img_index1]/2;
}
//ptr1[img_index1+idx] = (unsigned char) BOUND(ptr1[img_index1] + ptr2[img_index2] * 1.0,0,255);
Expand Down
3 changes: 3 additions & 0 deletions include/caffe/layers/annotated_data_layer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class AnnotatedDataLayer : public BasePrefetchingDataLayer<Dtype> {
bool single_class_; //for yolo segementation
YoloSegLabel label_map_;
int seg_label_maxima_;
int seg_scales_;
int seg_resize_width_;
int seg_resize_height_;
};

} // namespace caffe
Expand Down
77 changes: 77 additions & 0 deletions include/caffe/layers/segmentation_evaluate_layer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* @Author: Eric612
* @Date: 2019-03-11
* @https://github.com/eric612/Caffe-YOLOv3-Windows
* @https://github.com/eric612/MobileNet-YOLO
* Avisonic , ELAN microelectronics
*/
#ifdef USE_OPENCV
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#endif // USE_OPENCV
#ifndef CAFFE_SEGMENTATION_EVALUATE_LAYER_HPP_
#define CAFFE_SEGMENTATION_EVALUATE_LAYER_HPP_

#include <utility>
#include <vector>

#include "caffe/blob.hpp"
#include "caffe/layer.hpp"
#include "caffe/proto/caffe.pb.h"

namespace caffe {

/**
* @brief Generate the detection evaluation based on DetectionOutputLayer and
* ground truth bounding box labels.
*
* Intended for use with MultiBox detection method.
*
* NOTE: does not implement Backwards operation.
*/
template <typename Dtype>
class SegmentationEvaluateLayer : public Layer<Dtype> {
public:
explicit SegmentationEvaluateLayer(const LayerParameter& param)
: Layer<Dtype>(param) {}
virtual void LayerSetUp(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top);
virtual void Reshape(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top);

virtual inline const char* type() const { return "DetectionEvaluate"; }
virtual inline int ExactBottomBlobs() const { return 2; }
virtual inline int ExactNumTopBlobs() const { return 1; }

protected:
/**
* @brief Evaluate the detection output.
*
* @param bottom input Blob vector (exact 2)
* -# @f$ (1 \times 1 \times N \times 7) @f$
* N detection results.
* -# @f$ (1 \times 1 \times M \times 7) @f$
* M ground truth.
* @param top Blob vector (length 1)
* -# @f$ (1 \times 1 \times N \times 4) @f$
* N is the number of detections, and each row is:
* [image_id, label, confidence, true_pos, false_pos]
*/
virtual void Forward_cpu(const vector<Blob<Dtype>*>& bottom,
const vector<Blob<Dtype>*>& top);
/// @brief Not implemented
virtual void Backward_cpu(const vector<Blob<Dtype>*>& top,
const vector<bool>& propagate_down, const vector<Blob<Dtype>*>& bottom) {
NOT_IMPLEMENTED;
}
void visualization(const vector<Blob<Dtype>*>& bottom, const vector<Blob<Dtype>*>& top);
int num_classes_;
//std::vector<cv::Mat> seg_img_;
float threshold_;
int iter_;
};

} // namespace caffe

#endif // CAFFE_SEGMENTATION_EVALUATE_LAYER_HPP_
1 change: 1 addition & 0 deletions include/caffe/solver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ class Solver {
void TestAll();
void TestClassification(const int test_net_id = 0);
void TestDetection(const int test_net_id = 0);
void TestDetectionSeg(const int test_net_id = 0);
virtual void SnapshotSolverState(const string& model_filename) = 0;
virtual void RestoreSolverStateFromHDF5(const string& state_file) = 0;
virtual void RestoreSolverStateFromBinaryProto(const string& state_file) = 0;
Expand Down
8 changes: 4 additions & 4 deletions models/cityscapes/mobilenet_yolov3_solver.prototxt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
train_net: "models/cityscapes/mobilenet_yolov3_train.prototxt"
#test_net: "models/cityscapes/mobilenet_yolov3_test.prototxt"
#test_iter: 2000
#test_interval: 1000
test_net: "models/cityscapes/mobilenet_yolov3_test.prototxt"
test_iter: 500
test_interval: 1000
base_lr: 0.0005
display: 10
max_iter: 120000
Expand All @@ -20,6 +20,6 @@ stepvalue: 40000
stepvalue: 60000
iter_size: 16
type: "RMSProp"
eval_type: "detection"
eval_type: "detection_segmentation"
ap_version: "11point"
show_per_class_result: true
214 changes: 196 additions & 18 deletions models/cityscapes/mobilenet_yolov3_test.prototxt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ layer {
type: "AnnotatedData"
top: "data"
top: "label"
top: "seg_label"
include {
phase: TEST
}
Expand All @@ -22,14 +23,17 @@ layer {
}
}
data_param {
source: "examples/bus/bus_test_lmdb"
source: "examples/cityscapes/cityscapes_val_lmdb"
batch_size: 1
backend: LMDB
}
annotated_data_param {
single_class : false
#seg_resize_width : 2048
#seg_resize_height : 1024
batch_sampler {
}
label_map_file: "data/VOC0712/labelmap_voc.prototxt"
label_map_file: "data/cityscapes/labelmap_seg.prototxt"
}
}

Expand Down Expand Up @@ -2911,24 +2915,23 @@ layer {
#10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326

biases: 4
biases: 9
biases: 7
biases: 6
biases: 15
biases: 13
biases: 8
biases: 22
biases: 12
biases: 31
biases: 21
biases: 18
biases: 16
biases: 42
biases: 22
biases: 57
biases: 32
biases: 81
biases: 50
biases: 124
biases: 82
biases: 207
biases: 12
biases: 33
biases: 20
biases: 47
biases: 30
biases: 71
biases: 46
biases: 112
biases: 78
biases: 193
mask:6
mask:7
mask:8
Expand All @@ -2944,7 +2947,6 @@ layer {
mask_group_num:3
}
}

layer {
name: "detection_eval"
type: "DetectionEvaluate"
Expand All @@ -2960,3 +2962,179 @@ layer {
}
}

layer {
name: "conv25/dw"
type: "DepthwiseConvolution"
bottom: "conv20/sum"
top: "conv25/dw"
param {
lr_mult: 1
decay_mult: 1
}
convolution_param {
num_output: 256
bias_term: false
pad: 1
kernel_size: 3
group: 256
engine: CAFFE
weight_filler {
type: "msra"
}
}
}
layer {
name: "conv25/dw/bn"
type: "BatchNorm"
bottom: "conv25/dw"
top: "conv25/dw"
param {
lr_mult: 0
decay_mult: 0
}
param {
lr_mult: 0
decay_mult: 0
}
param {
lr_mult: 0
decay_mult: 0
}
}
layer {
name: "conv25/dw/scale"
type: "Scale"
bottom: "conv25/dw"
top: "conv25/dw"
param {
lr_mult: 1
decay_mult: 0.0
}
param {
lr_mult: 2
decay_mult: 0.0
}
scale_param {
filler {
value: 1
}
bias_term: true
bias_filler {
value: 0
}
}
}
layer {
name: "conv25/dw/relu"
type: "ReLU"
bottom: "conv25/dw"
top: "conv25/dw"
}
layer {
name: "conv25"
type: "Convolution"
bottom: "conv25/dw"
top: "conv25"
param {
lr_mult: 1
decay_mult: 1
}
convolution_param {
num_output: 256
bias_term: false
kernel_size: 1
weight_filler {
type: "msra"
}
}
}
layer {
name: "conv25/bn"
type: "BatchNorm"
bottom: "conv25"
top: "conv25"
param {
lr_mult: 0
decay_mult: 0
}
param {
lr_mult: 0
decay_mult: 0
}
param {
lr_mult: 0
decay_mult: 0
}
}
layer {
name: "conv25/scale"
type: "Scale"
bottom: "conv25"
top: "conv25"
param {
lr_mult: 1.0
decay_mult: 0.0
}
param {
lr_mult: 2.0
decay_mult: 0.0
}
scale_param {
filler {
value: 1
}
bias_term: true
bias_filler {
value: 0
}
}
}
layer {
name: "conv25/relu"
type: "ReLU"
bottom: "conv25"
top: "conv25"
}
layer {
name: "conv26"
type: "Convolution"
bottom: "conv25"
top: "conv26"
param {
lr_mult: 1
decay_mult: 1
}
param {
lr_mult: 2
decay_mult: 0
}
convolution_param {
num_output: 3 # channel = class
kernel_size: 1
pad: 0
stride: 1
weight_filler {
type: "msra"
}
bias_filler {
value: 0
}
}
}
layer {
name: "sigmoid"
bottom: "conv26"
top: "sigmoid"
type: "Sigmoid"
}
layer {
name: "segmentation_eval"
type: "SegmentationEvaluate"
bottom: "sigmoid"
bottom: "seg_label"
top: "segmentation_eval"

segmentation_evaluate_param {
num_classes: 3
}
}
Loading

0 comments on commit 02c455d

Please sign in to comment.