@@ -192,6 +192,59 @@ void SumOfSquaresCostLayer::backwardImp(Matrix& output,
192
192
outputG.sumOfSquaresBp (output, *label.value );
193
193
}
194
194
195
+ //
196
+ // class SmoothL1CostLayer
197
+ //
198
+
199
+ REGISTER_LAYER (smooth_l1, SmoothL1CostLayer);
200
+
201
+ bool SmoothL1CostLayer::init (const LayerMap& layerMap,
202
+ const ParameterMap& parameterMap) {
203
+ return CostLayer::init (layerMap, parameterMap);
204
+ }
205
+
206
+ void SmoothL1CostLayer::forwardImp (Matrix& output,
207
+ Argument& label,
208
+ Matrix& target) {
209
+ MatrixPtr targetCpu, outputCpu, labelCpu;
210
+ if (useGpu_) {
211
+ targetCpu =
212
+ Matrix::create (target.getHeight (), target.getWidth (), false , false );
213
+ outputCpu =
214
+ Matrix::create (output.getHeight (), output.getWidth (), false , false );
215
+ labelCpu = Matrix::create (
216
+ label.value ->getHeight (), label.value ->getWidth (), false , false );
217
+ targetCpu->copyFrom (target);
218
+ outputCpu->copyFrom (output);
219
+ labelCpu->copyFrom (*label.value );
220
+ targetCpu->smoothL1 (*outputCpu, *(labelCpu));
221
+ target.copyFrom (*targetCpu);
222
+ } else {
223
+ target.smoothL1 (output, *label.value );
224
+ }
225
+ }
226
+
227
+ void SmoothL1CostLayer::backwardImp (Matrix& output,
228
+ Argument& label,
229
+ Matrix& outputG) {
230
+ MatrixPtr outputGCpu, outputCpu, labelCpu;
231
+ if (useGpu_) {
232
+ outputGCpu =
233
+ Matrix::create (outputG.getHeight (), outputG.getWidth (), false , false );
234
+ outputCpu =
235
+ Matrix::create (output.getHeight (), output.getWidth (), false , false );
236
+ labelCpu = Matrix::create (
237
+ label.value ->getHeight (), label.value ->getWidth (), false , false );
238
+ outputGCpu->copyFrom (outputG);
239
+ outputCpu->copyFrom (output);
240
+ labelCpu->copyFrom (*label.value );
241
+ outputGCpu->smoothL1Bp (*outputCpu, *labelCpu);
242
+ outputG.copyFrom (*outputGCpu);
243
+ } else {
244
+ outputG.smoothL1Bp (output, *label.value );
245
+ }
246
+ }
247
+
195
248
//
196
249
// class RankingCost
197
250
//
0 commit comments