Context manager `open(file) as f` fixes (#7289)
* Flask context manager `open()` fix * Additional read context manager fixes
This commit is contained in:
parent
2181ef371e
commit
5f97001ed4
|
|
@ -72,7 +72,8 @@ download: |
|
||||||
imgs_path.mkdir(exist_ok=True, parents=True)
|
imgs_path.mkdir(exist_ok=True, parents=True)
|
||||||
lbs_path.mkdir(exist_ok=True, parents=True)
|
lbs_path.mkdir(exist_ok=True, parents=True)
|
||||||
|
|
||||||
image_ids = open(path / f'VOC{year}/ImageSets/Main/{image_set}.txt').read().strip().split()
|
with open(path / f'VOC{year}/ImageSets/Main/{image_set}.txt') as f:
|
||||||
|
image_ids = f.read().strip().split()
|
||||||
for id in tqdm(image_ids, desc=f'{image_set}{year}'):
|
for id in tqdm(image_ids, desc=f'{image_set}{year}'):
|
||||||
f = path / f'VOC{year}/JPEGImages/{id}.jpg' # old img path
|
f = path / f'VOC{year}/JPEGImages/{id}.jpg' # old img path
|
||||||
lb_path = (lbs_path / f.name).with_suffix('.txt') # new label path
|
lb_path = (lbs_path / f.name).with_suffix('.txt') # new label path
|
||||||
|
|
|
||||||
|
|
@ -407,7 +407,8 @@ def export_tfjs(keras_model, im, file, prefix=colorstr('TensorFlow.js:')):
|
||||||
f'--output_node_names="Identity,Identity_1,Identity_2,Identity_3" {f_pb} {f}'
|
f'--output_node_names="Identity,Identity_1,Identity_2,Identity_3" {f_pb} {f}'
|
||||||
subprocess.run(cmd, shell=True)
|
subprocess.run(cmd, shell=True)
|
||||||
|
|
||||||
json = open(f_json).read()
|
with open(f_json) as j:
|
||||||
|
json = j.read()
|
||||||
with open(f_json, 'w') as j: # sort JSON Identity_* in ascending order
|
with open(f_json, 'w') as j: # sort JSON Identity_* in ascending order
|
||||||
subst = re.sub(
|
subst = re.sub(
|
||||||
r'{"outputs": {"Identity.?.?": {"name": "Identity.?.?"}, '
|
r'{"outputs": {"Identity.?.?": {"name": "Identity.?.?"}, '
|
||||||
|
|
|
||||||
|
|
@ -378,7 +378,8 @@ class DetectMultiBackend(nn.Module):
|
||||||
return x.prune(tf.nest.map_structure(ge, inputs), tf.nest.map_structure(ge, outputs))
|
return x.prune(tf.nest.map_structure(ge, inputs), tf.nest.map_structure(ge, outputs))
|
||||||
|
|
||||||
gd = tf.Graph().as_graph_def() # graph_def
|
gd = tf.Graph().as_graph_def() # graph_def
|
||||||
gd.ParseFromString(open(w, 'rb').read())
|
with open(w, 'rb') as f:
|
||||||
|
gd.ParseFromString(f.read())
|
||||||
frozen_func = wrap_frozen_graph(gd, inputs="x:0", outputs="Identity:0")
|
frozen_func = wrap_frozen_graph(gd, inputs="x:0", outputs="Identity:0")
|
||||||
elif tflite or edgetpu: # https://www.tensorflow.org/lite/guide/python#install_tensorflow_lite_for_python
|
elif tflite or edgetpu: # https://www.tensorflow.org/lite/guide/python#install_tensorflow_lite_for_python
|
||||||
try: # https://coral.ai/docs/edgetpu/tflite-python/#update-existing-tf-lite-code-for-the-edge-tpu
|
try: # https://coral.ai/docs/edgetpu/tflite-python/#update-existing-tf-lite-code-for-the-edge-tpu
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,18 @@
|
||||||
"""Perform test request"""
|
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
|
||||||
|
"""
|
||||||
|
Perform test request
|
||||||
|
"""
|
||||||
|
|
||||||
import pprint
|
import pprint
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
DETECTION_URL = "http://localhost:5000/v1/object-detection/yolov5s"
|
DETECTION_URL = "http://localhost:5000/v1/object-detection/yolov5s"
|
||||||
TEST_IMAGE = "zidane.jpg"
|
IMAGE = "zidane.jpg"
|
||||||
|
|
||||||
image_data = open(TEST_IMAGE, "rb").read()
|
# Read image
|
||||||
|
with open(IMAGE, "rb") as f:
|
||||||
|
image_data = f.read()
|
||||||
|
|
||||||
response = requests.post(DETECTION_URL, files={"image": image_data}).json()
|
response = requests.post(DETECTION_URL, files={"image": image_data}).json()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
|
# YOLOv5 🚀 by Ultralytics, GPL-3.0 license
|
||||||
"""
|
"""
|
||||||
Run a Flask REST API exposing a YOLOv5s model
|
Run a Flask REST API exposing a YOLOv5s model
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import io
|
import io
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue