Skip to content

Commit 660f68c

Browse files
committed
update
1 parent 16f8acb commit 660f68c

File tree

1 file changed

+170
-0
lines changed

1 file changed

+170
-0
lines changed

README.md

+170
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,174 @@ void test(){
9494
//...
9595
//out就是结果
9696
}
97+
```
98+
99+
SSD训练
100+
```
101+
#include <cc_utils.h>
102+
using namespace cc;
103+
104+
class SSDMyDataLayer : public SSDDataLayer{
105+
public:
106+
SETUP_LAYERFUNC(SSDMyDataLayer);
107+
108+
SSDMyDataLayer(){
109+
this->datum_ = createAnnDatum();
110+
this->label_map_ = loadLabelMap("labelmap_voc.prototxt");
111+
}
112+
113+
virtual ~SSDMyDataLayer(){
114+
releaseAnnDatum(this->datum_);
115+
}
116+
117+
virtual int getBatchCacheSize(){
118+
return 3;
119+
}
120+
121+
virtual void* getAnnDatum(){
122+
if (!loadAnnDatum("00001.jpg", "00001.xml", 0, 0, 0, 0, true, "jpg", "xml", this->label_map_, this->datum_)){
123+
printf("无法加载.\n");
124+
exit(0);
125+
}
126+
return this->datum_;
127+
}
128+
129+
virtual void releaseAnnDatum(void* datum){
130+
}
131+
132+
private:
133+
void* datum_;
134+
void* label_map_;
135+
};
136+
137+
void main(){
138+
installRegister();
139+
INSTALL_LAYER(SSDMyDataLayer);
140+
141+
WPtr<Solver> solver = loadSolverFromPrototxt("solver.prototxt");
142+
solver->net()->copyTrainedParamFromFile("VGG_ILSVRC_16_layers_fc_reduced.caffemodel");
143+
//solver->Restore("models/blstmctc_iter_12111.solverstate");
144+
solver->Solve();
145+
}
146+
147+
prototxt的data层:
148+
layer {
149+
name: "data"
150+
type: "CPP"
151+
top: "data"
152+
top: "label"
153+
include {
154+
phase: TRAIN
155+
}
156+
cpp_param{
157+
type: "SSDMyDataLayer"
158+
}
159+
transform_param {
160+
mirror: true
161+
mean_value: 104
162+
mean_value: 117
163+
mean_value: 123
164+
resize_param {
165+
prob: 1
166+
resize_mode: WARP
167+
height: 300
168+
width: 300
169+
interp_mode: LINEAR
170+
interp_mode: AREA
171+
interp_mode: NEAREST
172+
interp_mode: CUBIC
173+
interp_mode: LANCZOS4
174+
}
175+
emit_constraint {
176+
emit_type: CENTER
177+
}
178+
}
179+
data_param {
180+
batch_size: 8
181+
}
182+
annotated_data_param {
183+
batch_sampler {
184+
max_sample: 1
185+
max_trials: 1
186+
}
187+
batch_sampler {
188+
sampler {
189+
min_scale: 0.3
190+
max_scale: 1.0
191+
min_aspect_ratio: 0.5
192+
max_aspect_ratio: 2.0
193+
}
194+
sample_constraint {
195+
min_jaccard_overlap: 0.1
196+
}
197+
max_sample: 1
198+
max_trials: 50
199+
}
200+
batch_sampler {
201+
sampler {
202+
min_scale: 0.3
203+
max_scale: 1.0
204+
min_aspect_ratio: 0.5
205+
max_aspect_ratio: 2.0
206+
}
207+
sample_constraint {
208+
min_jaccard_overlap: 0.3
209+
}
210+
max_sample: 1
211+
max_trials: 50
212+
}
213+
batch_sampler {
214+
sampler {
215+
min_scale: 0.3
216+
max_scale: 1.0
217+
min_aspect_ratio: 0.5
218+
max_aspect_ratio: 2.0
219+
}
220+
sample_constraint {
221+
min_jaccard_overlap: 0.5
222+
}
223+
max_sample: 1
224+
max_trials: 50
225+
}
226+
batch_sampler {
227+
sampler {
228+
min_scale: 0.3
229+
max_scale: 1.0
230+
min_aspect_ratio: 0.5
231+
max_aspect_ratio: 2.0
232+
}
233+
sample_constraint {
234+
min_jaccard_overlap: 0.7
235+
}
236+
max_sample: 1
237+
max_trials: 50
238+
}
239+
batch_sampler {
240+
sampler {
241+
min_scale: 0.3
242+
max_scale: 1.0
243+
min_aspect_ratio: 0.5
244+
max_aspect_ratio: 2.0
245+
}
246+
sample_constraint {
247+
min_jaccard_overlap: 0.9
248+
}
249+
max_sample: 1
250+
max_trials: 50
251+
}
252+
batch_sampler {
253+
sampler {
254+
min_scale: 0.3
255+
max_scale: 1.0
256+
min_aspect_ratio: 0.5
257+
max_aspect_ratio: 2.0
258+
}
259+
sample_constraint {
260+
max_jaccard_overlap: 1.0
261+
}
262+
max_sample: 1
263+
max_trials: 50
264+
}
265+
}
266+
}
97267
```

0 commit comments

Comments
 (0)