Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | @@ -12,6 +12,54 @@ def detect(inp): | |
| 12 | 
             
              #f"./yolov7/runs/detect/exp/{otp}"
         | 
| 13 |  | 
| 14 |  | 
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
|  | |
| 15 | 
             
            opt  = {
         | 
| 16 |  | 
| 17 | 
             
                "weights": "best.pt", # Path to weights file default weights are for nano model
         | 
|  | |
| 12 | 
             
              #f"./yolov7/runs/detect/exp/{otp}"
         | 
| 13 |  | 
| 14 |  | 
| 15 | 
            +
              
         | 
| 16 | 
            +
              
         | 
| 17 | 
            +
            import argparse
         | 
| 18 | 
            +
            from pathlib import Path
         | 
| 19 | 
            +
            import cv2
         | 
| 20 | 
            +
            import torch
         | 
| 21 | 
            +
            import numpy as np
         | 
| 22 | 
            +
            from numpy import random
         | 
| 23 | 
            +
            from models.experimental import attempt_load
         | 
| 24 | 
            +
            from utils.datasets import LoadStreams, LoadImages
         | 
| 25 | 
            +
            from utils.general import check_img_size, check_requirements, check_imshow, non_max_suppression, apply_classifier,scale_coords, xyxy2xywh, strip_optimizer, set_logging, increment_path
         | 
| 26 | 
            +
            from utils.plots import plot_one_box
         | 
| 27 | 
            +
            from utils.torch_utils import select_device, time_synchronized
         | 
| 28 | 
            +
             | 
| 29 | 
            +
             | 
| 30 | 
            +
            def letterbox(img, new_shape=(640, 640), color=(114, 114, 114), auto=True, scaleFill=False, scaleup=True, stride=32):
         | 
| 31 | 
            +
                # Resize and pad image while meeting stride-multiple constraints
         | 
| 32 | 
            +
                shape = img.shape[:2]  # current shape [height, width]
         | 
| 33 | 
            +
                if isinstance(new_shape, int):
         | 
| 34 | 
            +
                    new_shape = (new_shape, new_shape)
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                # Scale ratio (new / old)
         | 
| 37 | 
            +
                r = min(new_shape[0] / shape[0], new_shape[1] / shape[1])
         | 
| 38 | 
            +
                if not scaleup:  # only scale down, do not scale up (for better test mAP)
         | 
| 39 | 
            +
                    r = min(r, 1.0)
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                # Compute padding
         | 
| 42 | 
            +
                ratio = r, r  # width, height ratios
         | 
| 43 | 
            +
                new_unpad = int(round(shape[1] * r)), int(round(shape[0] * r))
         | 
| 44 | 
            +
                dw, dh = new_shape[1] - new_unpad[0], new_shape[0] - new_unpad[1]  # wh padding
         | 
| 45 | 
            +
                if auto:  # minimum rectangle
         | 
| 46 | 
            +
                    dw, dh = np.mod(dw, stride), np.mod(dh, stride)  # wh padding
         | 
| 47 | 
            +
                elif scaleFill:  # stretch
         | 
| 48 | 
            +
                    dw, dh = 0.0, 0.0
         | 
| 49 | 
            +
                    new_unpad = (new_shape[1], new_shape[0])
         | 
| 50 | 
            +
                    ratio = new_shape[1] / shape[1], new_shape[0] / shape[0]  # width, height ratios
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                dw /= 2  # divide padding into 2 sides
         | 
| 53 | 
            +
                dh /= 2
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                if shape[::-1] != new_unpad:  # resize
         | 
| 56 | 
            +
                    img = cv2.resize(img, new_unpad, interpolation=cv2.INTER_LINEAR)
         | 
| 57 | 
            +
                top, bottom = int(round(dh - 0.1)), int(round(dh + 0.1))
         | 
| 58 | 
            +
                left, right = int(round(dw - 0.1)), int(round(dw + 0.1))
         | 
| 59 | 
            +
                img = cv2.copyMakeBorder(img, top, bottom, left, right, cv2.BORDER_CONSTANT, value=color)  # add border
         | 
| 60 | 
            +
                return img, ratio, (dw, dh)
         | 
| 61 | 
            +
             | 
| 62 | 
            +
              
         | 
| 63 | 
             
            opt  = {
         | 
| 64 |  | 
| 65 | 
             
                "weights": "best.pt", # Path to weights file default weights are for nano model
         | 
