import os import sys sys.path.append("Monk_Object_Detection/12_tf_obj_1/lib/") from infer_detector import Infer gtf = Infer() # Model loading takes time on nano boards gtf.set_model_params('trt_fp16_dir/trt_graph.pb', "ship/classes.txt") # Running for the first time builds the tensorRT engine for the model based on the plan saved in trt_fp16_dir folder # Oputput will be saved as output.png scores, bboxes, labels = gtf.infer_on_image('ship/test/img5.jpg', thresh=0.5, img_size=300) # Run speed benchmark gtf.benchmark_for_speed('ship/test/img1.jpg', img_size=300)
sys.stdout = Unbuffered(sys.stdout) print("Predicting....") with open('obj_7_yolov3_infer.json') as json_file: system = json.load(json_file) system["conf_thresh"] = float(system["conf_thresh"]) system["iou_thresh"] = float(system["iou_thresh"]) class_file = system["class_file"] f = open(class_file, 'r') class_list = f.readlines() f.close() for i in range(len(class_list)): class_list[i] = class_list[i][:len(class_list[i]) - 1] gtf = Infer() gtf.Model(system["model"], class_list, system["weights"], use_gpu=True, input_size=416) output = gtf.Predict(system["img_file"], conf_thres=system["conf_thresh"], iou_thres=system["iou_thresh"]) print("Completed")
import sys import cv2 as cv sys.path.append("../lib") from utils.datasets import LoadWebcam from infer_detector import Infer infer=Infer(0) classPath="classes.txt" # weightsDir="../lib/weights/last_5epoch_2numgen.pt" weightsDir="../lib/weights/last_5epoch_2numgen.pt" infer.Model("yolov3", classPath, weightsDir, use_gpu=True, half_precision=True) web=LoadWebcam() iter(web) while True: imgPath,img,img0,_=next(web) cv.imwrite("webcamFrames/frame.jpg", img0) infer.Predict("D:\\Repo\\Monk_Object_Detection\\7_yolov3\HandsTrain\\webcamFrames\\frame.jpg") out=cv.imread("output/frame.jpg") cv.imshow("frame", out)
with open('obj_6_cornernet_lite_infer.json') as json_file: system = json.load(json_file) system["conf_thresh"] = float(system["conf_thresh"]) class_file = system["class_file"]; f = open(class_file, 'r'); class_list = f.readlines(); f.close(); for i in range(len(class_list)): class_list[i] = class_list[i][:len(class_list[i])-1] gtf = Infer(); gtf.Model(class_list, base=system["model"], model_path=system["weights"]) output = gtf.Predict(system["img_file"], vis_thresh=system["conf_thresh"], output_img="output.jpg"); print("Completed")
sys.stdout = Unbuffered(sys.stdout) print("Predicting....") with open('obj_4_efficientdet_infer.json') as json_file: system = json.load(json_file) if (system["use_gpu"] == "yes"): system["use_gpu"] = True else: system["use_gpu"] = False system["conf_thresh"] = float(system["conf_thresh"]) class_file = system["class_file"] f = open(class_file, 'r') class_list = f.readlines() f.close() for i in range(len(class_list)): class_list[i] = class_list[i][:len(class_list[i]) - 1] gtf = Infer() gtf.Model(model_dir=system["weights_dir"]) scores, labels, boxes = gtf.Predict(system["img_file"], class_list, vis_threshold=system["conf_thresh"]) print("Completed")
timg_dir = "images"; tset_dir = "Train"; vroot_dir = "Root_Dir"; vcoco_dir = "Coco_style"; vimg_dir = "images"; vset_dir = "Val"; model.Train_Dataset(troot_dir, tcoco_dir, timg_dir, tset_dir, batch_size=8, image_size=352, use_gpu=True) model.Val_Dataset(vroot_dir, vcoco_dir, vimg_dir, vset_dir) model.Model(model_name="resnet34"); # resnet 50 brought cuda memory error. model.Set_Hyperparams(lr=0.0001, val_interval=1, print_interval=20) model.Train(num_epochs=300,output_model_name="karen_model.pt"); from infer_detector import Infer gtf = Infer(); gtf.Model(model_path="/content/karen_model.pt"); #predictions are quite bad at the moment. class_list=[] with open("/content/Root_Dir/Coco_style/annotations/classes.txt") as file: for line in file: class_list.append(line.rstrip("\n")) class_list=class_list[:-1] img_p="/content/Images_and_Labels/Images/0000002_00005_d_0000014_jpg.rf.555bf2106d899e56d45da0a48295f04c.jpg" scores, labels, boxes = gtf.Predict(img_p, class_list, vis_threshold=0.4); from IPython.display import Image Image(filename='output.jpg')
import cv2 as cv import os import sys import shutil import time sys.path.append("../lib") from infer_detector import Infer from utils.datasets import LoadWebcam infer = Infer(0) classPath = "classes.txt" weightsDir = "../lib/weights/last_7e_2n.pt" #weightsDir="../lib/weights/yolov3-tiny-8e-2n.pt" infer.Model("yolov3", classPath, weightsDir, use_gpu=True) # start=time.time() # disp=2 # fps=0 cap = cv.VideoCapture(0) prev = 0 new = 0 while True: ret, frame = cap.read() # frame=cv.flip(frame, 1) #frame=cv.resize(frame, (416, 416)) print(frame.shape) cv.imwrite("webcamFrames/frame.jpg", frame) font = cv.FONT_HERSHEY_SIMPLEX new = time.time() fps = 1 / (new - prev) prev = new fps = int(fps)