This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0. Source | https://github.com/qqwweee/keras-yolo3 | |||
---|---|---|---|---|
1. Training | 1.1. create mydata_train.txt | ref: train.txt | ||
1.2. create mydata_class.txt | ref: model_data/voc_classes.txt | |||
1.3. change train.py to train_mydata.py | 1.3.1. annotation_path = 'mydata_train.txt' | ref: 1.1 | ||
1.3.2. classes_path = 'model_data/mydata_classes.txt' | ref: 1.2 | |||
1.3.3. create_model with load_pretrained=False | optional (if pre-trained weight doesn't work) | |||
1.3.4. model.save('mymodel.h5') | save model and weight for prediction | |||
1.3.5. change epochs from 50 to 5 | optional (check if it works or not) | |||
1.3.6. change batch_size from 32 to 8 | optional (if it has some memory problems) | |||
1.3.7. remove training in the second stage | optional (if the firs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
_________________________________________________________________ | |
Layer (type) Output Shape Param # | |
================================================================= | |
input_1 (InputLayer) (None, 224, 224, 3) 0 | |
_________________________________________________________________ | |
conv1_pad (ZeroPadding2D) (None, 225, 225, 3) 0 | |
_________________________________________________________________ | |
conv1 (Conv2D) (None, 112, 112, 32) 864 | |
_________________________________________________________________ | |
conv1_bn (BatchNormalization (None, 112, 112, 32) 128 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from keras.applications.inception_v3 import InceptionV3 | |
from keras.models import Model | |
from keras.layers import Dense, GlobalAveragePooling2D | |
# parameters for architecture | |
input_shape = (224, 224, 3) | |
num_classes = 6 | |
conv_size = 32 | |
# parameters for training |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from keras.models import Sequential | |
from keras.layers import Conv2D, MaxPooling2D, Flatten, Dense | |
# parameters for architecture | |
input_shape = (224, 224, 3) | |
num_classes = 6 | |
conv_size = 32 | |
# parameters for training | |
batch_size = 32 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from keras.applications.mobilenet import MobileNet | |
from keras.models import Model | |
from keras.layers import Dense, GlobalAveragePooling2D | |
# parameters for architecture | |
input_shape = (224, 224, 3) | |
num_classes = 6 | |
conv_size = 32 | |
# parameters for training |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
classes_90 = ["background", "person", "bicycle", "car", "motorcycle", | |
"airplane", "bus", "train", "truck", "boat", "traffic light", "fire hydrant", | |
"unknown", "stop sign", "parking meter", "bench", "bird", "cat", "dog", "horse", | |
"sheep", "cow", "elephant", "bear", "zebra", "giraffe", "unknown", "backpack", | |
"umbrella", "unknown", "unknown", "handbag", "tie", "suitcase", "frisbee", "skis", | |
"snowboard", "sports ball", "kite", "baseball bat", "baseball glove", "skateboard", | |
"surfboard", "tennis racket", "bottle", "unknown", "wine glass", "cup", "fork", "knife", | |
"spoon", "bowl", "banana", "apple", "sandwich", "orange", "broccoli", "carrot", "hot dog", | |
"pizza", "donut", "cake", "chair", "couch", "potted plant", "bed", "unknown", "dining table", | |
"unknown", "unknown", "toilet", "unknown", "tv", "laptop", "mouse", "remote", "keyboard", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
classes_80 = ["person", "bicycle", "car", "motorcycle", | |
"airplane", "bus", "train", "truck", "boat", "traffic light", "fire hydrant", | |
"stop sign", "parking meter", "bench", "bird", "cat", "dog", "horse", | |
"sheep", "cow", "elephant", "bear", "zebra", "giraffe", "backpack", | |
"umbrella", "handbag", "tie", "suitcase", "frisbee", "skis", | |
"snowboard", "sports ball", "kite", "baseball bat", "baseball glove", "skateboard", | |
"surfboard", "tennis racket", "bottle", "wine glass", "cup", "fork", "knife", | |
"spoon", "bowl", "banana", "apple", "sandwich", "orange", "broccoli", "carrot", "hot dog", | |
"pizza", "donut", "cake", "chair", "couch", "potted plant", "bed", "dining table", | |
"toilet", "tv", "laptop", "mouse", "remote", "keyboard", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# loop 845 bounding boxes | |
for i in range(Net_YOLO_pred.shape[0]): | |
# get the confidence on the object | |
confidence_on_box = Net_YOLO_pred[i][4] | |
# find the class index with the highest probability | |
probability_list = Net_YOLO_pred[i][5:] | |
class_index = probability_list.argmax(axis=0) | |
probability_on_class = probability_list[class_index] | |
# get the score | |
score = confidence_on_box * probability_on_class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# loop 100 bounding boxes | |
for detection in Net_SSD_pred[0,0,:,:]: | |
# get the class index | |
class_index = int(detection[1]) | |
# get the score | |
score = float(detection[2]) | |
# draw the bounding box | |
if score > threshold: | |
left = detection[3] * cols | |
top = detection[4] * rows |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pb = 'frozen_inference_graph.pb' | |
pbt = 'ssd_mobilenet_v1_coco_2017_11_17.pbtxt' | |
Net_SSD = cv.dnn.readNetFromTensorflow(pb,pbt) | |
Net_SSD.setInput(cv.dnn.blobFromImage(img, 1.0/127.5, (300, 300), (127.5, 127.5, 127.5), swapRB = True, crop = False)) | |
Net_SSD_pred = Net_SSD.forward() | |
print(">>> SSD/MobileNet prediction shape = ", Net_SSD_pred.shape) |