@@ -16,7 +16,7 @@ namespace TensorFlowNET.Examples
1616 public class ObjectDetection : Python , IExample
1717 {
1818 public int Priority => 11 ;
19- public bool Enabled { get ; set ; } = false ;
19+ public bool Enabled { get ; set ; } = true ;
2020 public string Name => "Object Detection" ;
2121 public float MIN_SCORE = 0.5f ;
2222
@@ -36,15 +36,11 @@ public bool Run()
3636 var graph = new Graph ( ) . as_default ( ) ;
3737 graph . Import ( Path . Join ( modelDir , pbFile ) ) ;
3838
39- var tensorNum = graph . OperationByName ( "num_detections" ) . outputs [ 0 ] ;
40- var tensorBoxes = graph . OperationByName ( "detection_boxes" ) . outputs [ 0 ] ;
41- var tensorScores = graph . OperationByName ( "detection_scores" ) . outputs [ 0 ] ;
42- var tensorClasses = graph . OperationByName ( "detection_classes" ) . outputs [ 0 ] ;
43-
44- var imgTensor = graph . OperationByName ( "image_tensor" ) . outputs [ 0 ] ;
45-
46-
47-
39+ Tensor tensorNum = graph . OperationByName ( "num_detections" ) ;
40+ Tensor tensorBoxes = graph . OperationByName ( "detection_boxes" ) ;
41+ Tensor tensorScores = graph . OperationByName ( "detection_scores" ) ;
42+ Tensor tensorClasses = graph . OperationByName ( "detection_classes" ) ;
43+ Tensor imgTensor = graph . OperationByName ( "image_tensor" ) ;
4844 Tensor [ ] outTensorArr = new Tensor [ ] { tensorNum , tensorBoxes , tensorScores , tensorClasses } ;
4945
5046 with ( tf . Session ( graph ) , sess =>
@@ -61,39 +57,19 @@ public bool Run()
6157
6258 public void PrepareData ( )
6359 {
64- if ( ! Directory . Exists ( modelDir ) )
65- Directory . CreateDirectory ( modelDir ) ;
66-
67- if ( ! File . Exists ( Path . Join ( modelDir , "ssd_mobilenet_v1_coco.tar.gz" ) ) )
68- {
69- // get model file
70- string url = "http://download.tensorflow.org/models/object_detection/ssd_mobilenet_v1_coco_2018_01_28.tar.gz" ;
71-
72- Utility . Web . Download ( url , modelDir , "ssd_mobilenet_v1_coco.tar.gz" ) ;
73- }
74-
75- if ( ! File . Exists ( Path . Join ( modelDir , "frozen_inference_graph.pb" ) ) )
76- {
77- Utility . Compress . ExtractTGZ ( Path . Join ( modelDir , "ssd_mobilenet_v1_coco.tar.gz" ) , "./" ) ;
78- }
60+ // get model file
61+ string url = "http://download.tensorflow.org/models/object_detection/ssd_mobilenet_v1_coco_2018_01_28.tar.gz" ;
62+ Web . Download ( url , modelDir , "ssd_mobilenet_v1_coco.tar.gz" ) ;
7963
64+ Compress . ExtractTGZ ( Path . Join ( modelDir , "ssd_mobilenet_v1_coco.tar.gz" ) , "./" ) ;
8065
8166 // download sample picture
82- if ( ! Directory . Exists ( imageDir ) )
83- Directory . CreateDirectory ( imageDir ) ;
84-
85- if ( ! File . Exists ( Path . Join ( imageDir , "input.jpg" ) ) )
86- {
87- string url = $ "https://github.com/tensorflow/models/raw/master/research/object_detection/test_images/image2.jpg";
88- Utility . Web . Download ( url , imageDir , "input.jpg" ) ;
89- }
67+ url = $ "https://github.com/tensorflow/models/raw/master/research/object_detection/test_images/image2.jpg";
68+ Web . Download ( url , imageDir , "input.jpg" ) ;
9069
9170 // download the pbtxt file
92- if ( ! File . Exists ( Path . Join ( modelDir , "mscoco_label_map.pbtxt" ) ) )
93- {
94- string url = $ "https://raw.githubusercontent.com/tensorflow/models/master/research/object_detection/data/mscoco_label_map.pbtxt";
95- Utility . Web . Download ( url , modelDir , "mscoco_label_map.pbtxt" ) ;
96- }
71+ url = $ "https://raw.githubusercontent.com/tensorflow/models/master/research/object_detection/data/mscoco_label_map.pbtxt";
72+ Web . Download ( url , modelDir , "mscoco_label_map.pbtxt" ) ;
9773 }
9874
9975 private NDArray ReadTensorFromImageFile ( string file_name )
0 commit comments