From c159e692fd7ac79c93deb3a248ddcc5bd8c280c3 Mon Sep 17 00:00:00 2001 From: ManojKumarMuru Date: Mon, 24 Oct 2022 18:09:47 +0200 Subject: [PATCH] Weights are now downloaded automatically --- examples/efficientdet/efficientdet_model.py | 11 +++++++---- examples/efficientdet/infer_efficientdet.py | 10 ++++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/examples/efficientdet/efficientdet_model.py b/examples/efficientdet/efficientdet_model.py index b0bc6e6d9..347d1047d 100644 --- a/examples/efficientdet/efficientdet_model.py +++ b/examples/efficientdet/efficientdet_model.py @@ -1,5 +1,6 @@ from tensorflow.keras.layers import Input from tensorflow.keras.models import Model +from tensorflow.keras.utils import get_file from anchors import build_prior_boxes from efficientdet_blocks import BiFPN, BoxNet, ClassNet @@ -7,7 +8,7 @@ from utils import create_multibox_head WEIGHT_PATH = ( - '/home/manummk95/Desktop/efficientdet_working/required/weights/') + 'https://github.com/oarriaga/altamira-data/releases/download/v0.16/') def EfficientDet(num_classes, base_weights, head_weights, input_shape, @@ -83,9 +84,11 @@ def EfficientDet(num_classes, base_weights, head_weights, input_shape, if (((base_weights == 'COCO') and (head_weights == 'COCO')) or ((base_weights == 'COCO') and (head_weights is None))): - weights_path = (WEIGHT_PATH + model_name + '-' + - str(base_weights) + '-' + str(head_weights) + - '_weights.hdf5') + model_filename = (model_name + '-' + str(base_weights) + '-' + + str(head_weights) + '_weights.hdf5') + weights_path = get_file(model_filename, WEIGHT_PATH + model_filename, + cache_subdir='paz/models') + print('Loading %s model weights' % weights_path) model.load_weights(weights_path) model.prior_boxes = build_prior_boxes( diff --git a/examples/efficientdet/infer_efficientdet.py b/examples/efficientdet/infer_efficientdet.py index 249497831..316db146e 100644 --- a/examples/efficientdet/infer_efficientdet.py +++ b/examples/efficientdet/infer_efficientdet.py @@ -1,15 +1,21 @@ from paz.backend.image import show_image, write_image from paz.datasets import get_class_names +from tensorflow.keras.utils import get_file from detection import DetectSingleShot from efficientdet import EFFICIENTDETD0 from utils import raw_images +WEIGHT_PATH = ( + 'https://github.com/oarriaga/altamira-data/releases/download/v0.16/') +WEIGHT_FILE = 'efficientdet-d0-VOC-VOC_weights.hdf5' + if __name__ == "__main__": model = EFFICIENTDETD0(num_classes=21, base_weights='COCO', head_weights=None) - model.load_weights("/home/manummk95/Desktop/efficientdet_working/temp/" - "weight/weights.209-3.73.hdf5") + weights_path = get_file(WEIGHT_FILE, WEIGHT_PATH + WEIGHT_FILE, + cache_subdir='paz/models') + model.load_weights(weights_path) detections = DetectSingleShot(model, get_class_names('VOC'), 0.5, 0.45)(raw_images) show_image(detections['image'])