decorate open by with
parent
0c3c266a3c
commit
e4780174d1
|
@ -23,9 +23,11 @@ py_version = sys.version_info[0]
|
||||||
|
|
||||||
def predict(image_path, server):
|
def predict(image_path, server):
|
||||||
if py_version == 2:
|
if py_version == 2:
|
||||||
image = base64.b64encode(open(image_path).read())
|
with open(image_path) as f:
|
||||||
|
image = base64.b64encode(f.read())
|
||||||
else:
|
else:
|
||||||
image = base64.b64encode(open(image_path, "rb").read()).decode("utf-8")
|
with open(image_path, "rb") as f:
|
||||||
|
image = base64.b64encode(f.read()).decode("utf-8")
|
||||||
req = json.dumps({"feed": [{"image": image}], "fetch": ["prediction"]})
|
req = json.dumps({"feed": [{"image": image}], "fetch": ["prediction"]})
|
||||||
r = requests.post(
|
r = requests.post(
|
||||||
server, data=req, headers={"Content-Type": "application/json"})
|
server, data=req, headers={"Content-Type": "application/json"})
|
||||||
|
|
|
@ -154,10 +154,12 @@ cutout_op = Cutout(n_holes=1, length=112)
|
||||||
|
|
||||||
ops = [decode_op, resize_op, cutout_op]
|
ops = [decode_op, resize_op, cutout_op]
|
||||||
|
|
||||||
imgs_dir = image_path
|
imgs_dir = "imgs_dir"
|
||||||
fnames = os.listdir(imgs_dir)
|
file_names = os.listdir(imgs_dir)
|
||||||
for f in fnames:
|
for file_name in file_names:
|
||||||
data = open(os.path.join(imgs_dir, f)).read()
|
file_path = os.join(imgs_dir, file_name)
|
||||||
|
with open(file_path) as f:
|
||||||
|
data = f.read()
|
||||||
img = transform(data, ops)
|
img = transform(data, ops)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -74,10 +74,12 @@ autoaugment_op = ImageNetPolicy()
|
||||||
|
|
||||||
ops = [decode_op, resize_op, autoaugment_op]
|
ops = [decode_op, resize_op, autoaugment_op]
|
||||||
|
|
||||||
imgs_dir = 图像路径
|
imgs_dir = "imgs_dir"
|
||||||
fnames = os.listdir(imgs_dir)
|
file_names = os.listdir(imgs_dir)
|
||||||
for f in fnames:
|
for file_name in file_names:
|
||||||
data = open(os.path.join(imgs_dir, f)).read()
|
file_path = os.join(imgs_dir, file_name)
|
||||||
|
with open(file_path) as f:
|
||||||
|
data = f.read()
|
||||||
img = transform(data, ops)
|
img = transform(data, ops)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,8 @@ class CompCars(Dataset):
|
||||||
label_path = os.path.join(self._label_root,
|
label_path = os.path.join(self._label_root,
|
||||||
l[0].split('.')[0] + '.txt')
|
l[0].split('.')[0] + '.txt')
|
||||||
assert os.path.exists(label_path)
|
assert os.path.exists(label_path)
|
||||||
bbox = open(label_path).readlines()[-1].strip().split()
|
with open(label_path) as f:
|
||||||
|
bbox = f.readlines()[-1].strip().split()
|
||||||
bbox = [int(x) for x in bbox]
|
bbox = [int(x) for x in bbox]
|
||||||
self.images.append(os.path.join(self._img_root, l[0]))
|
self.images.append(os.path.join(self._img_root, l[0]))
|
||||||
self.labels.append(int(l[1]))
|
self.labels.append(int(l[1]))
|
||||||
|
|
Loading…
Reference in New Issue