Skip to content

Commit 75e26ff

Browse files
committed
Add requirements check and improve code
1 parent 9b3b34c commit 75e26ff

7 files changed

Lines changed: 32 additions & 20 deletions

File tree

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@
101101
|-------------------------|-------------|-------------------------------|---------------------------------------------------------------------|
102102
| `--weights` | `str` | `yolov7.pt` | Path(s) to model weights (`.pt` file). |
103103
| `--download` | `flag` | `False` | Download model weights automatically. |
104-
| `--no-download` | `flag` | `False` | Do not download model weights if they already exist. |
105104
| `--source` | `str` | `None` | Source for inference (file, folder, or `0` for webcam). |
106105
| `--img-size` | `int` | `640` | Inference image size in pixels. |
107106
| `--conf-thres` | `float` | `0.25` | Object confidence threshold. |

assets/demo.mp4

4.04 MB
Binary file not shown.

detect.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,19 @@ def detect():
195195
opt = parser.parse_args()
196196
print(opt)
197197

198+
check_requirements([
199+
"matplotlib>=3.2.2",
200+
"numpy>=1.18.5",
201+
"opencv-python>=4.1.1",
202+
"Pillow>=7.1.2",
203+
"PyYAML>=5.3.1",
204+
"requests>=2.23.0",
205+
"scipy>=1.4.1",
206+
"torch>=1.7.0,!=1.12.0",
207+
"torchvision>=0.8.1,!=0.13.0",
208+
"tqdm>=4.41.0",
209+
"protobuf==4.25.8",
210+
])
198211
if not os.path.exists(opt.weights[0]):
199212
print('⚠️ Model weights not found. Attempting to download now...')
200213
download('./')

detect_and_track.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from models.experimental import attempt_load
99
from utils.datasets import LoadStreams, LoadImages
10-
from utils.general import check_img_size, \
10+
from utils.general import check_img_size, check_requirements, \
1111
check_imshow, non_max_suppression, apply_classifier, \
1212
scale_coords, strip_optimizer, set_logging, \
1313
increment_path
@@ -281,7 +281,6 @@ def detect():
281281
parser = argparse.ArgumentParser()
282282
parser.add_argument('--weights', nargs='+', type=str, default='yolov7.pt', help='model.pt path(s)')
283283
parser.add_argument('--download', action='store_true', help='download model weights automatically')
284-
parser.add_argument('--no-download', dest='download', action='store_false',help='not download model weights if already exist')
285284
parser.add_argument('--source', type=str, default=None, help='source') # file/folder, 0 for webcam
286285
parser.add_argument('--img-size', type=int, default=640, help='inference size (pixels)')
287286
parser.add_argument('--conf-thres', type=float, default=0.25, help='object confidence threshold')
@@ -306,8 +305,22 @@ def detect():
306305
parser.set_defaults(download=True)
307306
opt = parser.parse_args()
308307
print(opt)
309-
#check_requirements(exclude=('pycocotools', 'thop'))
310-
if opt.download and not os.path.exists(''.join(opt.weights)):
308+
check_requirements([
309+
"matplotlib>=3.2.2",
310+
"numpy>=1.18.5",
311+
"opencv-python>=4.1.1",
312+
"Pillow>=7.1.2",
313+
"PyYAML>=5.3.1",
314+
"requests>=2.23.0",
315+
"scipy>=1.4.1",
316+
"torch>=1.7.0,!=1.12.0",
317+
"torchvision>=0.8.1,!=0.13.0",
318+
"tqdm>=4.41.0",
319+
"protobuf==4.25.8",
320+
"filterpy",
321+
"scikit-image"
322+
])
323+
if not os.path.exists(''.join(opt.weights)):
311324
print('Model weights not found. Attempting to download now...')
312325
download('./')
313326

models/experimental.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@ def forward(self, x, augment=False):
2121

2222
def attempt_load(weights, map_location=None):
2323
# Loads an ensemble of models weights=[a,b,c] or a single model weights=[a] or weights=a
24-
from packaging import version
25-
weights_only = False if version.parse(torch.__version__) >= version.parse("2.6") else True
2624
model = Ensemble()
2725
for w in weights if isinstance(weights, list) else [weights]:
28-
ckpt = torch.load(w, map_location=map_location, weights_only=weights_only) # load
26+
ckpt = torch.load(w, map_location=map_location, weights_only=False) # load with weights only=False https://pytorch.org/docs/stable/generated/torch.load.html
2927
model.append(ckpt['ema' if ckpt.get('ema') else 'model'].float().fuse().eval()) # FP32 model
3028

3129
# Compatibility updates

models/yolo.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,6 @@ def convert(self, z):
8989
return box, score
9090

9191

92-
def check_anchor_order(m):
93-
# Check anchor order against stride order for YOLO Detect() module m, and correct if necessary
94-
a = m.anchor_grid.prod(-1).view(-1) # anchor area
95-
da = a[-1] - a[0] # delta a
96-
ds = m.stride[-1] - m.stride[0] # delta s
97-
if da.sign() != ds.sign(): # same order
98-
print('Reversing anchor order')
99-
m.anchors[:] = m.anchors.flip(0)
100-
m.anchor_grid[:] = m.anchor_grid.flip(0)
101-
102-
10392
class Model(nn.Module):
10493
def __init__(self, cfg='yolor-csp-c.yaml', ch=3, nc=None, anchors=None): # model, input channels, number of classes
10594
super(Model, self).__init__()

utils/torch_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def git_describe(path=Path(__file__).parent): # path must be a directory
6262

6363
def select_device(device='', batch_size=None):
6464
# device = 'cpu' or '0' or '0,1,2,3'
65-
s = f'YOLOv7 🚀 {git_describe() or date_modified()} torch {torch.__version__}' # string
65+
s = f'YOLOv7 🚀 {git_describe() or date_modified()} torch {torch.__version__}' # string
6666
cpu = device.lower() == 'cpu'
6767
if cpu:
6868
os.environ['CUDA_VISIBLE_DEVICES'] = '-1' # force torch.cuda.is_available() = False

0 commit comments

Comments
 (0)