|
@@ -14,6 +14,23 @@ from utils.general import check_img_size, check_requirements, check_imshow, non_
|
|
from utils.plots import plot_one_box
|
|
from utils.plots import plot_one_box
|
|
from utils.torch_utils import select_device, load_classifier, time_synchronized, TracedModel
|
|
from utils.torch_utils import select_device, load_classifier, time_synchronized, TracedModel
|
|
|
|
|
|
|
|
+import matplotlib.pyplot as plt
|
|
|
|
+from time import sleep
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+class frame_:
|
|
|
|
+ def __init__(self):
|
|
|
|
+
|
|
|
|
+ self.model = attempt_load(opt.weights, map_location=opt.device).half() # load FP32 model -> FP16
|
|
|
|
+ self.stride = int(self.model.stride.max()) # model stride
|
|
|
|
+ self.imgsz = check_img_size(self.imgsz, s=self.stride) # check img_size
|
|
|
|
+ self.x = LoadStreams(opt.source, img_size=opt.imgsz, stride=opt.stride)
|
|
|
|
+
|
|
|
|
+ def inference(cls):
|
|
|
|
+ y = cls.model(cls.x)
|
|
|
|
+ print(y)
|
|
|
|
+ return y
|
|
|
|
+
|
|
|
|
|
|
def detect(save_img=False):
|
|
def detect(save_img=False):
|
|
source, weights, view_img, save_txt, imgsz, trace = opt.source, opt.weights, opt.view_img, opt.save_txt, opt.img_size, not opt.no_trace
|
|
source, weights, view_img, save_txt, imgsz, trace = opt.source, opt.weights, opt.view_img, opt.save_txt, opt.img_size, not opt.no_trace
|
|
@@ -51,6 +68,7 @@ def detect(save_img=False):
|
|
vid_path, vid_writer = None, None
|
|
vid_path, vid_writer = None, None
|
|
if webcam:
|
|
if webcam:
|
|
view_img = check_imshow()
|
|
view_img = check_imshow()
|
|
|
|
+ print(f'view_img : {view_img}')
|
|
cudnn.benchmark = True # set True to speed up constant image size inference
|
|
cudnn.benchmark = True # set True to speed up constant image size inference
|
|
dataset = LoadStreams(source, img_size=imgsz, stride=stride)
|
|
dataset = LoadStreams(source, img_size=imgsz, stride=stride)
|
|
else:
|
|
else:
|
|
@@ -126,7 +144,7 @@ def detect(save_img=False):
|
|
|
|
|
|
if save_img or view_img: # Add bbox to image
|
|
if save_img or view_img: # Add bbox to image
|
|
label = f'{names[int(cls)]} {conf:.2f}'
|
|
label = f'{names[int(cls)]} {conf:.2f}'
|
|
- plot_one_box(xyxy, im0, label=label, color=colors[int(cls)], line_thinckness=1)
|
|
|
|
|
|
+ plot_one_box(xyxy, im0, label=label, color=colors[int(cls)], line_thickness=1)
|
|
|
|
|
|
# Print time (inference + NMS)
|
|
# Print time (inference + NMS)
|
|
print(f'{s}Done. ({(1E3 * (t2 - t1)):.1f}ms) Inference, ({(1E3 * (t3 - t2)):.1f}ms) NMS')
|
|
print(f'{s}Done. ({(1E3 * (t2 - t1)):.1f}ms) Inference, ({(1E3 * (t3 - t2)):.1f}ms) NMS')
|
|
@@ -134,6 +152,7 @@ def detect(save_img=False):
|
|
# Stream results
|
|
# Stream results
|
|
if view_img:
|
|
if view_img:
|
|
cv2.imshow(str(p), im0)
|
|
cv2.imshow(str(p), im0)
|
|
|
|
+ # plt.imshow(str(p), im0)
|
|
cv2.waitKey(1) # 1 millisecond
|
|
cv2.waitKey(1) # 1 millisecond
|
|
|
|
|
|
# Save results (image with detections)
|
|
# Save results (image with detections)
|
|
@@ -165,7 +184,7 @@ def detect(save_img=False):
|
|
|
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
parser = argparse.ArgumentParser()
|
|
parser = argparse.ArgumentParser()
|
|
- parser.add_argument('--weights', nargs='+', type=str, default='Public/pretrained/yolov7_training.pt', help='model.pt path(s)')
|
|
|
|
|
|
+ parser.add_argument('--weights', nargs='+', type=str, default='best.pt', help='model.pt path(s)')
|
|
parser.add_argument('--source', type=str, default='inference/images', help='source') # file/folder, 0 for webcam
|
|
parser.add_argument('--source', type=str, default='inference/images', help='source') # file/folder, 0 for webcam
|
|
parser.add_argument('--img-size', type=int, default=640, help='inference size (pixels)')
|
|
parser.add_argument('--img-size', type=int, default=640, help='inference size (pixels)')
|
|
parser.add_argument('--conf-thres', type=float, default=0.25, help='object confidence threshold')
|
|
parser.add_argument('--conf-thres', type=float, default=0.25, help='object confidence threshold')
|
|
@@ -183,8 +202,10 @@ if __name__ == '__main__':
|
|
parser.add_argument('--name', default='exp', help='save results to project/name')
|
|
parser.add_argument('--name', default='exp', help='save results to project/name')
|
|
parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment')
|
|
parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment')
|
|
parser.add_argument('--no-trace', action='store_true', help='don`t trace model')
|
|
parser.add_argument('--no-trace', action='store_true', help='don`t trace model')
|
|
|
|
+
|
|
|
|
+ parser.add_argument('--stream', default=False, help='stream')
|
|
opt = parser.parse_args()
|
|
opt = parser.parse_args()
|
|
- print(opt)
|
|
|
|
|
|
+ # print(opt)
|
|
#check_requirements(exclude=('pycocotools', 'thop'))
|
|
#check_requirements(exclude=('pycocotools', 'thop'))
|
|
|
|
|
|
with torch.no_grad():
|
|
with torch.no_grad():
|
|
@@ -194,3 +215,14 @@ if __name__ == '__main__':
|
|
strip_optimizer(opt.weights)
|
|
strip_optimizer(opt.weights)
|
|
else:
|
|
else:
|
|
detect()
|
|
detect()
|
|
|
|
+ # if opt.stream == True:
|
|
|
|
+ # @app.get("/video")
|
|
|
|
+ # def video():
|
|
|
|
+ # # StringResponse함수를 return하고,
|
|
|
|
+ # # 인자로 OpenCV에서 가져온 "바이트"이미지와 type을 명시
|
|
|
|
+ # return Response(get_stream_video(), mimetype="multipart/x-mixed-replace; boundary=frame")
|
|
|
|
+ # else: detect()
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|