Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 36 additions & 20 deletions detect.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
"""
Usage:
$ python detect.py --model model_name --model_location model_path.pt --input_location image_path

model_name = [detr, ssd, fasterrcnn, yolov5, yolor, efficientdet]
if yolov5 you are in app/yolov5/:
model_path.pt & image_path should be relative paths


"""


import argparse
import cv2
import matplotlib.pyplot as plt
Expand All @@ -13,13 +25,11 @@
if __name__ == '__main__':
# intialize the parser
parser = argparse.ArgumentParser(
description='Predict using tick detection models'
)

description='Predict using tick detection models')
# arguments
parser.add_argument('--model', help='Model to use for tick object detection [detr, ssd, fasterrcnn, yolov5, yolor, efficientdet]')
parser.add_argument('--model_location' help='location of pretrained model')
parser.add_argument('--input_location', help='location of input')
parser.add_argument('--model', type=str, help='Model to use for tick object detection [detr, ssd, fasterrcnn, yolov5, yolor, efficientdet]')
parser.add_argument('--model_location', type=str, help='location of pretrained model')
parser.add_argument('--input_location', type=str, help='location of input image')
# parser.add_argument('--output_location', help='location of output')

# Parse the arguments
Expand All @@ -29,6 +39,7 @@
input_location = args.input_location
# output_location = args.output_location


if model=='detr':
first_class_index = 1
assert(first_class_index in [0, 1])
Expand Down Expand Up @@ -111,9 +122,9 @@
for path in paths.values():
if not os.path.exists(path):
if os.name == 'posix':
!mkdir -p {path}
os.mkdir(path)
if os.name == 'nt':
!mkdir {path}
os.mkdir(path)

import os
import tensorflow as tf
Expand All @@ -140,7 +151,7 @@ def detect_fn(image):
import cv2
import numpy as np
from matplotlib import pyplot as plt
%matplotlib inline
#%matplotlib inline

category_index = label_map_util.create_category_index_from_labelmap(files['LABELMAP'])

Expand Down Expand Up @@ -225,12 +236,17 @@ def detect_fn(image):


elif model=='yolov5':
!cd yolov5
!python detect.py --source image_location --weights model_location --conf-thres 0.5
import os
#yolov5_path = 'icarda_yolov_zip/icarda_yolov/app/yolov5'
yolov5_path = 'app/yolov5'
os.chdir(yolov5_path)
os.system('python detect.py --source ' + input_location + ' --weights ' + model_location)

elif model=='yolor':
!cd yolor
!python detect.py --source image_location --cfg cfg/yolor_p6.cfg --weights model_location --conf 0.5 --img-size 640 --device 0
import os
yolor_path = ''
os.chdi(yolor_path)
os.system('python detect.py --source '+ image_location +' --weights ' + model_location)

elif model=='efficientdet':
CUSTOM_MODEL_NAME = 'efficientdet'
Expand All @@ -255,11 +271,11 @@ def detect_fn(image):
}

for path in paths.values():
if not os.path.exists(path):
if os.name == 'posix':
!mkdir -p {path}
if os.name == 'nt':
!mkdir {path}
if not os.path.exists(path):
if os.name == 'posix':
os.mkdir(path)
if os.name == 'nt':
os.mkdir(path)

import os
import tensorflow as tf
Expand All @@ -286,7 +302,7 @@ def detect_fn(image):
import cv2
import numpy as np
from matplotlib import pyplot as plt
%matplotlib inline
#%matplotlib inline

category_index = label_map_util.create_category_index_from_labelmap(files['LABELMAP'])

Expand Down Expand Up @@ -325,4 +341,4 @@ def detect_fn(image):

else:
print('Model does not exist')