glenn-jocher commited on
Commit
4200674
·
unverified ·
1 Parent(s): 4890499

Add yolov5/ to sys.path() for *.py subdir exec (#2949)

Browse files

* Add yolov5/ to sys.path() for *.py subdir exec

* Update export.py

Files changed (2) hide show
  1. models/export.py +2 -1
  2. models/yolo.py +3 -2
models/export.py CHANGED
@@ -7,8 +7,9 @@ Usage:
7
  import argparse
8
  import sys
9
  import time
 
10
 
11
- sys.path.append('./') # to run '$ python *.py' files in subdirectories
12
 
13
  import torch
14
  import torch.nn as nn
 
7
  import argparse
8
  import sys
9
  import time
10
+ from pathlib import Path
11
 
12
+ sys.path.append(Path(__file__).parent.parent.absolute().__str__()) # to run '$ python *.py' files in subdirectories
13
 
14
  import torch
15
  import torch.nn as nn
models/yolo.py CHANGED
@@ -4,8 +4,9 @@ import argparse
4
  import logging
5
  import sys
6
  from copy import deepcopy
 
7
 
8
- sys.path.append('./') # to run '$ python *.py' files in subdirectories
9
  logger = logging.getLogger(__name__)
10
 
11
  from models.common import *
@@ -267,7 +268,7 @@ if __name__ == '__main__':
267
  # Create model
268
  model = Model(opt.cfg).to(device)
269
  model.train()
270
-
271
  # Profile
272
  # img = torch.rand(8 if torch.cuda.is_available() else 1, 3, 320, 320).to(device)
273
  # y = model(img, profile=True)
 
4
  import logging
5
  import sys
6
  from copy import deepcopy
7
+ from pathlib import Path
8
 
9
+ sys.path.append(Path(__file__).parent.parent.absolute().__str__()) # to run '$ python *.py' files in subdirectories
10
  logger = logging.getLogger(__name__)
11
 
12
  from models.common import *
 
268
  # Create model
269
  model = Model(opt.cfg).to(device)
270
  model.train()
271
+
272
  # Profile
273
  # img = torch.rand(8 if torch.cuda.is_available() else 1, 3, 320, 320).to(device)
274
  # y = model(img, profile=True)