@@ -241,25 +241,93 @@ static int test_squeezenet(const ncnn::Option& opt, int load_model_type, float e
241
241
return check_top2 (cls_scores, epsilon);
242
242
}
243
243
244
- class MySoftmax : public ncnn ::Layer
244
+ class MyConvolution : public ncnn ::Layer
245
245
{
246
246
public:
247
- MySoftmax ()
247
+ MyConvolution ()
248
248
{
249
- one_blob_only = true ;
250
- support_inplace = true ;
249
+ impl = ncnn::create_layer (" Convolution" );
250
+
251
+ one_blob_only = impl->one_blob_only ;
252
+ support_inplace = impl->support_inplace ;
253
+
254
+ support_packing = impl->support_packing ;
255
+ support_vulkan = impl->support_vulkan ;
256
+ support_bf16_storage = impl->support_bf16_storage ;
257
+ support_fp16_storage = impl->support_fp16_storage ;
258
+ support_int8_storage = impl->support_int8_storage ;
259
+ support_image_storage = impl->support_image_storage ;
260
+ }
261
+
262
+ ~MyConvolution ()
263
+ {
264
+ delete impl;
265
+ }
266
+
267
+ virtual int load_param (const ncnn::ParamDict& pd)
268
+ {
269
+ #if NCNN_VULKAN
270
+ impl->vkdev = vkdev;
271
+ #endif // NCNN_VULKAN
272
+
273
+ return impl->load_param (pd);
274
+ }
275
+
276
+ virtual int load_model (const ncnn::ModelBin& mb)
277
+ {
278
+ return impl->load_model (mb);
279
+ }
280
+
281
+ virtual int create_pipeline (const ncnn::Option& opt)
282
+ {
283
+ int ret = impl->create_pipeline (opt);
284
+
285
+ one_blob_only = impl->one_blob_only ;
286
+ support_inplace = impl->support_inplace ;
287
+
288
+ support_packing = impl->support_packing ;
289
+ support_vulkan = impl->support_vulkan ;
290
+ support_bf16_storage = impl->support_bf16_storage ;
291
+ support_fp16_storage = impl->support_fp16_storage ;
292
+ support_int8_storage = impl->support_int8_storage ;
293
+ support_image_storage = impl->support_image_storage ;
294
+
295
+ return ret;
296
+ }
297
+
298
+ virtual int destroy_pipeline (const ncnn::Option& opt)
299
+ {
300
+ return impl->destroy_pipeline (opt);
301
+ }
302
+
303
+ virtual int forward (const ncnn::Mat& bottom_blob, ncnn::Mat& top_blob, const ncnn::Option& opt) const
304
+ {
305
+ return impl->forward (bottom_blob, top_blob, opt);
306
+ }
307
+
308
+ #if NCNN_VULKAN
309
+ virtual int upload_model (ncnn::VkTransfer& cmd, const ncnn::Option& opt)
310
+ {
311
+ return impl->upload_model (cmd, opt);
251
312
}
252
313
253
- virtual int forward_inplace ( ncnn::Mat& bottom_top_blob, const ncnn::Option& /* opt*/ ) const
314
+ virtual int forward ( const ncnn::VkMat& bottom_blob, ncnn::VkMat& top_blob, ncnn::VkCompute& cmd, const ncnn::Option& opt) const
254
315
{
255
- bottom_top_blob.fill (0 .f );
256
- bottom_top_blob[123 ] = 0 .5f ;
257
- bottom_top_blob[456 ] = 0 .1f ;
258
- return 0 ;
316
+ return impl->forward (bottom_blob, top_blob, cmd, opt);
259
317
}
318
+
319
+ virtual int forward (const ncnn::VkImageMat& bottom_blob, ncnn::VkImageMat& top_blob, ncnn::VkCompute& cmd, const ncnn::Option& opt) const
320
+ {
321
+ return impl->forward (bottom_blob, top_blob, cmd, opt);
322
+ }
323
+ #endif // NCNN_VULKAN
324
+
325
+ private:
326
+ ncnn::Layer* impl;
260
327
};
261
328
262
- DEFINE_LAYER_CREATOR (MySoftmax)
329
+ DEFINE_LAYER_CREATOR (MyConvolution)
330
+ DEFINE_LAYER_DESTROYER(MyConvolution)
263
331
264
332
static int test_squeezenet_overwrite_softmax(const ncnn::Option& opt, int load_model_type, float epsilon = 0.001 )
265
333
{
@@ -279,7 +347,7 @@ static int test_squeezenet_overwrite_softmax(const ncnn::Option& opt, int load_m
279
347
if (load_model_type == 0 )
280
348
{
281
349
// load from plain model file
282
- squeezenet.register_custom_layer (" Softmax " , MySoftmax_layer_creator );
350
+ squeezenet.register_custom_layer (" Convolution " , MyConvolution_layer_creator, MyConvolution_layer_destroyer );
283
351
squeezenet.load_param (MODEL_DIR " /squeezenet_v1.1.param" );
284
352
285
353
// test random feature disabled bits
@@ -296,7 +364,7 @@ static int test_squeezenet_overwrite_softmax(const ncnn::Option& opt, int load_m
296
364
if (load_model_type == 1 )
297
365
{
298
366
// load from plain model memory
299
- squeezenet.register_custom_layer (" Softmax " , MySoftmax_layer_creator );
367
+ squeezenet.register_custom_layer (" Convolution " , MyConvolution_layer_creator, MyConvolution_layer_destroyer );
300
368
param_str = read_file_string (MODEL_DIR " /squeezenet_v1.1.param" );
301
369
model_data = read_file_content (MODEL_DIR " /squeezenet_v1.1.bin" );
302
370
squeezenet.load_param_mem ((const char *)param_str.c_str ());
@@ -305,14 +373,14 @@ static int test_squeezenet_overwrite_softmax(const ncnn::Option& opt, int load_m
305
373
if (load_model_type == 2 )
306
374
{
307
375
// load from binary model file
308
- squeezenet.register_custom_layer (ncnn::layer_to_index (" Softmax " ), MySoftmax_layer_creator );
376
+ squeezenet.register_custom_layer (ncnn::layer_to_index (" Convolution " ), MyConvolution_layer_creator, MyConvolution_layer_destroyer );
309
377
squeezenet.load_param_bin (MODEL_DIR " /squeezenet_v1.1.param.bin" );
310
378
squeezenet.load_model (MODEL_DIR " /squeezenet_v1.1.bin" );
311
379
}
312
380
if (load_model_type == 3 )
313
381
{
314
382
// load from binary model memory
315
- squeezenet.register_custom_layer (ncnn::layer_to_index (" Softmax " ), MySoftmax_layer_creator );
383
+ squeezenet.register_custom_layer (ncnn::layer_to_index (" Convolution " ), MyConvolution_layer_creator, MyConvolution_layer_destroyer );
316
384
param_data = read_file_content (MODEL_DIR " /squeezenet_v1.1.param.bin" );
317
385
model_data = read_file_content (MODEL_DIR " /squeezenet_v1.1.bin" );
318
386
squeezenet.load_param ((const unsigned char *)param_data);
@@ -345,7 +413,7 @@ static int test_squeezenet_overwrite_softmax(const ncnn::Option& opt, int load_m
345
413
cls_scores[j] = out[j];
346
414
}
347
415
348
- return cls_scores[ 123 ] == 0 . 5f && cls_scores[ 456 ] == 0 . 1f ? 0 : - 1 ;
416
+ return check_top2 ( cls_scores, epsilon) ;
349
417
}
350
418
351
419
int main ()
0 commit comments