h = image.shape[0] w = image.shape[1] input_image_shape = tf.constant([h, w], dtype=tf.dtypes.float32) img_tensor = resize_image_with_pad(image) img_tensor = tf.dtypes.cast(img_tensor, dtype=tf.dtypes.float32) # img_tensor = img_tensor / 255.0 yolo_output = model(img_tensor, training=False) boxes, scores, classes = Inference( yolo_output=yolo_output, input_image_shape=input_image_shape).get_final_boxes() image_with_boxes = draw_boxes_on_image(cv2.imread(image_dir), boxes, scores, classes) return image_with_boxes if __name__ == '__main__': # GPU settings gpus = tf.config.list_physical_devices(device_type="GPU") if gpus: for gpu in gpus: tf.config.experimental.set_memory_growth(device=gpu, enable=True) # load model yolo_v3 = YOLOV3(out_channels=3 * (CATEGORY_NUM + 5)) yolo_v3.load_weights(filepath=save_model_dir + "saved_model") # inference image = single_image_inference(image_dir=test_picture_dir, model=yolo_v3) cv2.namedWindow("detect result", flags=cv2.WINDOW_NORMAL) cv2.imshow("detect result", image) cv2.waitKey(0)
input_shape=[IMAGE_HEIGHT, IMAGE_WIDTH]).generate_label() return true_label if __name__ == '__main__': # GPU settings gpus = tf.config.list_physical_devices(device_type="GPU") if gpus: for gpu in gpus: tf.config.experimental.set_memory_growth(device=gpu, enable=True) # dataset train_dataset, train_count = generate_dataset() net = YOLOV3(out_channels=3 * (CATEGORY_NUM + 5)) print_model_summary(network=net) if load_weights_before_training: net.load_weights(filepath=save_model_dir + "epoch-{}".format(load_weights_from_epoch)) print("Successfully load weights!") else: load_weights_from_epoch = -1 # loss and optimizer yolo_loss = YoloLoss() lr_schedule = tf.keras.optimizers.schedules.ExponentialDecay( initial_learning_rate=0.001, decay_steps=5000, decay_rate=0.96,