'anchors': [[10, 14], [23, 27], [37, 58], [81, 82], [135, 169], [344, 319]], 'anchors_mask': [[1, 2, 3], [3, 4, 5]], 'image_shape': (416, 416), 'num_classes': 80, 'score_threshold': 0.6, 'iou_threshold': 0.3, 'batch_size': 2, 'drop_rate': 0.2, 'block_size': 3 } class_name = get_classes('./coco_classes.txt') model = creat_CSPYOLO(**default) load_weights(model, './yolov4-tiny.weights') img = cv2.imread('./kite.jpg') img = resiresize_img(img) img = padding_img(img) pred_img = np.expand_dims(img, axis=0).astype(np.float32) / 255 result = model.predict(pred_img) boxes, class_, score = output_result(result, **default) draw_img(img, boxes, class_, score, class_name, **default) cv2.imwrite('./predict.jpg', img) cv2.imshow('img', img) cv2.waitKey(0) cv2.destroyAllWindows()
boxes = preprocess_true_boxes(loc, **self.model_dict) image_data.append(img) y_true.append(boxes) image_data = (np.array(image_data) / 255).astype(np.float32) y_true = np.array(y_true) return image_data, y_true if __name__ == "__main__": model = creat_CSPYOLO(**train_default) if train_default['use_pretrain']: custom = False if train_default['num_classes'] == 80 else True load_weights(model, './yolov4.weights', custom_cls=custom) model.summary() annotation_path = 'path' log_dir = 'path' classes_path = 'path' class_name = get_classes(classes_path) xmls = os.listdir(annotation_path) total_train = len(xmls) callbacks = [tf.keras.callbacks.ModelCheckpoint(filepath= log_dir + 'best_loss.h5', save_best_only=True, save_weights_only=True, monitor='loss',
[36, 75], [76, 55], [72, 146], [142, 110], [192, 243], [459, 401]], 'anchors_mask': [[0, 1, 2], [3, 4, 5], [6, 7, 8]], 'image_shape': (608, 608), 'num_classes': 80, 'score_threshold': 0.6, 'iou_threshold': 0.3, 'batch_size': 2, 'drop_rate' : 0.2, 'block_size' : 3 } class_name = get_classes('./coco_classes.txt') model = creat_CSPYOLO(**default) load_weights(model, './yolov4.weights') img = cv2.imread('./kite.jpg') img = resiresize_img(img) img = padding_img(img) pred_img = np.expand_dims(img, axis=0).astype(np.float32) / 255 result = model.predict(pred_img) boxes, class_, score = output_result(result, **default) draw_img(img, boxes, class_, score, class_name, **default) cv2.imwrite('./predict.jpg', img) cv2.imshow('img', img) cv2.waitKey(0) cv2.destroyAllWindows()