Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
wz authored and wz committed Sep 15, 2020
2 parents a5bf0da + 1048148 commit b2183c1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
# create model
model = MobileNetV2(num_classes=5)
# load model weights
model_weight_path = weights_path
model.load_state_dict(torch.load(model_weight_path, map_location=device))
model.load_state_dict(torch.load(weights_path, map_location=device))
model.to(device)
model.eval()

# load class info
json_file = open(class_json_path, 'r')
json_file = open(class_json_path, 'rb')
class_indict = json.load(json_file)


Expand All @@ -41,7 +41,7 @@ def transform_image(image_bytes):
image = Image.open(io.BytesIO(image_bytes))
if image.mode != "RGB":
raise ValueError("input file does not RGB image...")
return my_transforms(image).unsqueeze(0)
return my_transforms(image).unsqueeze(0).to(device)


def get_prediction(image_bytes):
Expand All @@ -56,7 +56,7 @@ def get_prediction(image_bytes):
text = [template.format(k, v) for k, v in index_pre]
return_info = {"result": text}
except Exception as e:
return_info = {"result": str(e)}
return_info = {"result": [str(e)]}
return return_info


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Flask==1.1.1
Flask_Cors==3.0.9
Pillow==7.2.0

0 comments on commit b2183c1

Please sign in to comment.