Unverified 提交 238da321 authored 作者: Glenn Jocher's avatar Glenn Jocher 提交者: GitHub

Security3 (#10944)

* Security improvements * Security improvements * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: 's avatarpre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
上级 61407c93
...@@ -19,6 +19,7 @@ import argparse ...@@ -19,6 +19,7 @@ import argparse
import math import math
import os import os
import random import random
import subprocess
import sys import sys
import time import time
from copy import deepcopy from copy import deepcopy
...@@ -597,7 +598,8 @@ def main(opt, callbacks=Callbacks()): ...@@ -597,7 +598,8 @@ def main(opt, callbacks=Callbacks()):
# ei = [isinstance(x, (int, float)) for x in hyp.values()] # evolvable indices # ei = [isinstance(x, (int, float)) for x in hyp.values()] # evolvable indices
evolve_yaml, evolve_csv = save_dir / 'hyp_evolve.yaml', save_dir / 'evolve.csv' evolve_yaml, evolve_csv = save_dir / 'hyp_evolve.yaml', save_dir / 'evolve.csv'
if opt.bucket: if opt.bucket:
os.system(f'gsutil cp gs://{opt.bucket}/evolve.csv {evolve_csv}') # download evolve.csv if exists subprocess.run(
f'gsutil cp gs://{opt.bucket}/evolve.csv {evolve_csv}'.split()) # download evolve.csv if exists
for _ in range(opt.evolve): # generations to evolve for _ in range(opt.evolve): # generations to evolve
if evolve_csv.exists(): # if evolve.csv exists: select best hyps and mutate if evolve_csv.exists(): # if evolve.csv exists: select best hyps and mutate
......
...@@ -23,6 +23,7 @@ Usage - formats: ...@@ -23,6 +23,7 @@ Usage - formats:
import argparse import argparse
import json import json
import os import os
import subprocess
import sys import sys
from multiprocessing.pool import ThreadPool from multiprocessing.pool import ThreadPool
from pathlib import Path from pathlib import Path
...@@ -461,7 +462,7 @@ def main(opt): ...@@ -461,7 +462,7 @@ def main(opt):
r, _, t = run(**vars(opt), plots=False) r, _, t = run(**vars(opt), plots=False)
y.append(r + t) # results and times y.append(r + t) # results and times
np.savetxt(f, y, fmt='%10.4g') # save np.savetxt(f, y, fmt='%10.4g') # save
os.system('zip -r study.zip study_*.txt') subprocess.run('zip -r study.zip study_*.txt'.split())
plot_val_study(x=x) # plot plot_val_study(x=x) # plot
else: else:
raise NotImplementedError(f'--task {opt.task} not in ("train", "val", "test", "speed", "study")') raise NotImplementedError(f'--task {opt.task} not in ("train", "val", "test", "speed", "study")')
......
...@@ -19,6 +19,7 @@ import argparse ...@@ -19,6 +19,7 @@ import argparse
import math import math
import os import os
import random import random
import subprocess
import sys import sys
import time import time
from copy import deepcopy from copy import deepcopy
...@@ -571,7 +572,8 @@ def main(opt, callbacks=Callbacks()): ...@@ -571,7 +572,8 @@ def main(opt, callbacks=Callbacks()):
# ei = [isinstance(x, (int, float)) for x in hyp.values()] # evolvable indices # ei = [isinstance(x, (int, float)) for x in hyp.values()] # evolvable indices
evolve_yaml, evolve_csv = save_dir / 'hyp_evolve.yaml', save_dir / 'evolve.csv' evolve_yaml, evolve_csv = save_dir / 'hyp_evolve.yaml', save_dir / 'evolve.csv'
if opt.bucket: if opt.bucket:
os.system(f'gsutil cp gs://{opt.bucket}/evolve.csv {evolve_csv}') # download evolve.csv if exists subprocess.run(
f'gsutil cp gs://{opt.bucket}/evolve.csv {evolve_csv}'.split()) # download evolve.csv if exists
for _ in range(opt.evolve): # generations to evolve for _ in range(opt.evolve): # generations to evolve
if evolve_csv.exists(): # if evolve.csv exists: select best hyps and mutate if evolve_csv.exists(): # if evolve.csv exists: select best hyps and mutate
......
...@@ -50,7 +50,8 @@ def safe_download(file, url, url2=None, min_bytes=1E0, error_msg=''): ...@@ -50,7 +50,8 @@ def safe_download(file, url, url2=None, min_bytes=1E0, error_msg=''):
if file.exists(): if file.exists():
file.unlink() # remove partial downloads file.unlink() # remove partial downloads
LOGGER.info(f'ERROR: {e}\nRe-attempting {url2 or url} to {file}...') LOGGER.info(f'ERROR: {e}\nRe-attempting {url2 or url} to {file}...')
os.system(f"curl -# -L '{url2 or url}' -o '{file}' --retry 3 -C -") # curl download, retry and resume on fail subprocess.run(
f"curl -# -L '{url2 or url}' -o '{file}' --retry 3 -C -".split()) # curl download, retry and resume on fail
finally: finally:
if not file.exists() or file.stat().st_size < min_bytes: # check if not file.exists() or file.stat().st_size < min_bytes: # check
if file.exists(): if file.exists():
......
...@@ -631,8 +631,7 @@ def download(url, dir='.', unzip=True, delete=True, curl=False, threads=1, retry ...@@ -631,8 +631,7 @@ def download(url, dir='.', unzip=True, delete=True, curl=False, threads=1, retry
for i in range(retry + 1): for i in range(retry + 1):
if curl: if curl:
s = 'sS' if threads > 1 else '' # silent s = 'sS' if threads > 1 else '' # silent
r = os.system( r = subprocess.run(f'curl -# -{s}L "{url}" -o "{f}" --retry 9 -C -'.split())
f'curl -# -{s}L "{url}" -o "{f}" --retry 9 -C -') # curl download with retry, continue
success = r == 0 success = r == 0
else: else:
torch.hub.download_url_to_file(url, f, progress=threads == 1) # torch download torch.hub.download_url_to_file(url, f, progress=threads == 1) # torch download
......
...@@ -22,6 +22,7 @@ Usage - formats: ...@@ -22,6 +22,7 @@ Usage - formats:
import argparse import argparse
import json import json
import os import os
import subprocess
import sys import sys
from pathlib import Path from pathlib import Path
...@@ -397,7 +398,7 @@ def main(opt): ...@@ -397,7 +398,7 @@ def main(opt):
r, _, t = run(**vars(opt), plots=False) r, _, t = run(**vars(opt), plots=False)
y.append(r + t) # results and times y.append(r + t) # results and times
np.savetxt(f, y, fmt='%10.4g') # save np.savetxt(f, y, fmt='%10.4g') # save
os.system('zip -r study.zip study_*.txt') subprocess.run('zip -r study.zip study_*.txt'.split())
plot_val_study(x=x) # plot plot_val_study(x=x) # plot
else: else:
raise NotImplementedError(f'--task {opt.task} not in ("train", "val", "test", "speed", "study")') raise NotImplementedError(f'--task {opt.task} not in ("train", "val", "test", "speed", "study")')
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论