Skip to content
This repository has been archived by the owner on Jul 24, 2023. It is now read-only.

Commit

Permalink
mvp
Browse files Browse the repository at this point in the history
  • Loading branch information
robmarkcole committed Apr 5, 2021
1 parent 0188ce5 commit e2dc55d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
venv/
venv/
# *tmp.jpg
25 changes: 10 additions & 15 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,9 @@

app = Flask(__name__)

RESULT_FOLDER = os.path.join('static')
app.config['RESULT_FOLDER'] = RESULT_FOLDER

model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True, force_reload=True).autoshape() # for PIL/cv2/np inputs and NMS
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True).autoshape() # force_reload=True
model.eval()

def get_prediction(img_bytes):
img = Image.open(io.BytesIO(img_bytes))
results = model(img, size=640) # includes NMS
return results

@app.route('/', methods=['GET', 'POST'])
def predict():
if request.method == 'POST':
Expand All @@ -30,13 +22,16 @@ def predict():
return

img_bytes = file.read()
results = get_prediction(img_bytes)
results.print()
results.save() # save as results1.jpg, results2.jpg... etc.
os.rename("results0.jpg", "static/results0.jpg")
img = Image.open(io.BytesIO(img_bytes))
img.save('/tmp/tmp.jpg')

# Reopen
img = Image.open('/tmp/tmp.jpg')
results = model(img, size=640)

results.display(save=True, save_dir='static')
return redirect('static/tmp.jpg')

full_filename = os.path.join(app.config['RESULT_FOLDER'], 'results0.jpg')
return redirect('static/results0.jpg')
return render_template('index.html')


Expand Down
Binary file added static/tmp.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 1 addition & 2 deletions tests/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

# Results
results.print()
results.save() # or .show()
results.show()
# print(results.tolist())

# Data
# print(results.xyxy[0]) # print img1 predictions (pixels)

0 comments on commit e2dc55d

Please sign in to comment.