Skip to content

Commit 91f6e16

Browse files
model exporter + raccoon detection demo
1 parent 4cde8d3 commit 91f6e16

File tree

14 files changed

+308
-58
lines changed

14 files changed

+308
-58
lines changed

README.md

Lines changed: 111 additions & 52 deletions
Large diffs are not rendered by default.

data/samples/clean_raccoon.mp4

671 KB
Binary file not shown.
8.01 MB
Loading

detect_objects.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def DetectFromVideo(detector, Video_path, save_output=False, output_dir='output/
1313
output_path = os.path.join(output_dir, 'detection_'+ Video_path.split("/")[-1])
1414
frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
1515
frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
16-
out = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*"mp4v"), 25, (frame_width, frame_height))
16+
out = cv2.VideoWriter(output_path, cv2.VideoWriter_fourcc(*"mp4v"), 30, (frame_width, frame_height))
1717

1818
while (cap.isOpened()):
1919
ret, img = cap.read()
@@ -65,7 +65,7 @@ def DetectImagesFromFolder(detector, images_dir, save_output=False, output_dir='
6565
parser.add_argument('--threshold', help='Detection Threshold', type=float, default=0.4)
6666
parser.add_argument('--images_dir', help='Directory to input images)', default='data/samples/images/')
6767
parser.add_argument('--video_path', help='Path to input video)', default='data/samples/pedestrian_test.mp4')
68-
parser.add_argument('--output_directory', help='Path to output images and video', default='data/output')
68+
parser.add_argument('--output_directory', help='Path to output images and video', default='data/samples/output')
6969
parser.add_argument('--video_input', help='Flag for video input, default: False', action='store_true') # default is false
7070
parser.add_argument('--save_output', help='Flag for save images and video with detections visualized, default: False',
7171
action='store_true') # default is false

detector.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,14 @@ def DisplayDetections(self, image, boxes_list, det_time=None):
5858
score = str(np.round(boxes_list[idx][-1], 2))
5959

6060
text = cls + ": " + score
61-
cv2.rectangle(img, (x_min, y_min), (x_max, y_max), (0, 255, 0), 2)
61+
cv2.rectangle(img, (x_min, y_min), (x_max, y_max), (0, 255, 0), 1)
6262
cv2.rectangle(img, (x_min, y_min - 20), (x_min, y_min), (255, 255, 255), -1)
63-
cv2.putText(img, text, (x_min + 5, y_min - 7), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 0, 0), 1)
63+
cv2.putText(img, text, (x_min + 5, y_min - 7), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 1)
6464

6565
if det_time != None:
66-
elapsed_time = str(det_time) + " ms"
67-
cv2.putText(img, elapsed_time, (25, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 0), 2)
66+
fps = round(1000. / det_time, 1)
67+
fps_txt = str(fps) + " FPS"
68+
cv2.putText(img, fps_txt, (25, 30), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 0), 2)
6869

6970
return img
7071

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
model_checkpoint_path: "ckpt-0"
2+
all_model_checkpoint_paths: "ckpt-0"
3+
all_model_checkpoint_timestamps: 1595859041.5022295
4+
last_preserved_timestamp: 1595859040.4026093
Binary file not shown.
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
model {
2+
ssd {
3+
num_classes: 1
4+
image_resizer {
5+
fixed_shape_resizer {
6+
height: 300
7+
width: 300
8+
}
9+
}
10+
feature_extractor {
11+
type: "ssd_mobilenet_v2_keras"
12+
depth_multiplier: 1.0
13+
min_depth: 16
14+
conv_hyperparams {
15+
regularizer {
16+
l2_regularizer {
17+
weight: 4e-05
18+
}
19+
}
20+
initializer {
21+
truncated_normal_initializer {
22+
mean: 0.0
23+
stddev: 0.03
24+
}
25+
}
26+
activation: RELU_6
27+
batch_norm {
28+
decay: 0.97
29+
center: true
30+
scale: true
31+
epsilon: 0.001
32+
train: true
33+
}
34+
}
35+
override_base_feature_extractor_hyperparams: true
36+
}
37+
box_coder {
38+
faster_rcnn_box_coder {
39+
y_scale: 10.0
40+
x_scale: 10.0
41+
height_scale: 5.0
42+
width_scale: 5.0
43+
}
44+
}
45+
matcher {
46+
argmax_matcher {
47+
matched_threshold: 0.4
48+
unmatched_threshold: 0.4
49+
ignore_thresholds: false
50+
negatives_lower_than_unmatched: true
51+
force_match_for_each_row: true
52+
use_matmul_gather: true
53+
}
54+
}
55+
similarity_calculator {
56+
iou_similarity {
57+
}
58+
}
59+
box_predictor {
60+
convolutional_box_predictor {
61+
conv_hyperparams {
62+
regularizer {
63+
l2_regularizer {
64+
weight: 4e-05
65+
}
66+
}
67+
initializer {
68+
random_normal_initializer {
69+
mean: 0.0
70+
stddev: 0.01
71+
}
72+
}
73+
activation: RELU_6
74+
batch_norm {
75+
decay: 0.97
76+
center: true
77+
scale: true
78+
epsilon: 0.001
79+
train: true
80+
}
81+
}
82+
min_depth: 0
83+
max_depth: 0
84+
num_layers_before_predictor: 0
85+
use_dropout: false
86+
dropout_keep_probability: 0.8
87+
kernel_size: 1
88+
box_code_size: 4
89+
apply_sigmoid_to_scores: false
90+
class_prediction_bias_init: -4.6
91+
}
92+
}
93+
anchor_generator {
94+
ssd_anchor_generator {
95+
num_layers: 6
96+
min_scale: 0.15
97+
max_scale: 0.95
98+
aspect_ratios: 1.0
99+
aspect_ratios: 2.0
100+
aspect_ratios: 0.5
101+
}
102+
}
103+
post_processing {
104+
batch_non_max_suppression {
105+
score_threshold: 0.001
106+
iou_threshold: 0.4
107+
max_detections_per_class: 100
108+
max_total_detections: 100
109+
}
110+
score_converter: SIGMOID
111+
}
112+
normalize_loss_by_num_matches: true
113+
loss {
114+
localization_loss {
115+
weighted_smooth_l1 {
116+
delta: 1.0
117+
}
118+
}
119+
classification_loss {
120+
weighted_sigmoid_focal {
121+
gamma: 2.0
122+
alpha: 0.75
123+
}
124+
}
125+
classification_weight: 1.0
126+
localization_weight: 1.0
127+
}
128+
encode_background_as_zeros: true
129+
normalize_loc_loss_by_codesize: true
130+
inplace_batchnorm_update: true
131+
freeze_batchnorm: false
132+
}
133+
}
134+
train_config {
135+
batch_size: 16
136+
data_augmentation_options {
137+
random_horizontal_flip {
138+
}
139+
}
140+
data_augmentation_options {
141+
ssd_random_crop {
142+
}
143+
}
144+
sync_replicas: true
145+
optimizer {
146+
momentum_optimizer {
147+
learning_rate {
148+
cosine_decay_learning_rate {
149+
learning_rate_base: 0.025
150+
total_steps: 3000
151+
warmup_learning_rate: 0.005
152+
warmup_steps: 100
153+
}
154+
}
155+
momentum_optimizer_value: 0.9
156+
}
157+
use_moving_average: false
158+
}
159+
fine_tune_checkpoint: "../models/ssd_mobilenet_v2_320x320_coco17_tpu-8/checkpoint/ckpt-0"
160+
num_steps: 3000
161+
startup_delay_steps: 0.0
162+
replicas_to_aggregate: 8
163+
max_number_of_boxes: 100
164+
unpad_groundtruth_tensors: false
165+
fine_tune_checkpoint_type: "detection"
166+
use_bfloat16: false
167+
fine_tune_checkpoint_version: V2
168+
}
169+
train_input_reader {
170+
label_map_path: "../models/raccoon_labelmap.pbtxt"
171+
tf_record_input_reader {
172+
input_path: "../data/raccoon_data/train.record"
173+
}
174+
}
175+
eval_config {
176+
metrics_set: "coco_detection_metrics"
177+
use_moving_averages: false
178+
}
179+
eval_input_reader {
180+
label_map_path: "../models/raccoon_labelmap.pbtxt"
181+
shuffle: false
182+
num_epochs: 1
183+
tf_record_input_reader {
184+
input_path: "../data/raccoon_data/val.record"
185+
}
186+
}

0 commit comments

Comments
 (0)