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

Commit

Permalink
Merge pull request #24 from robmarkcole/ISSUE19
Browse files Browse the repository at this point in the history
Update for current yolov5 release YOLOv5 2022-8-30
  • Loading branch information
robmarkcole authored Aug 30, 2022
2 parents 9278f5c + 59d26a0 commit 27e8f91
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ The model inference results are returned:
An example python script to perform inference using [requests](https://docs.python-requests.org/en/master/) is given in `tests/test_request.py`

## Run & Develop locally
Run locally and dev:
Run locally for dev, requirements mostly originate from [yolov5](https://github.com/ultralytics/yolov5/blob/master/requirements.txt):
* `python3 -m venv venv`
* `source venv/bin/activate`
* `(venv) $ pip install -r requirements.txt`
Expand Down
15 changes: 5 additions & 10 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
flask
requests
black

matplotlib>=3.2.2
numpy>=1.18.5
opencv-python>=4.1.2
Pillow
opencv-python>=4.1.1
Pillow>=7.1.2
PyYAML>=5.3.1
requests>=2.23.0
scipy>=1.4.1
torch>=1.7.0
torchvision>=0.8.1
tqdm>=4.41.0

tensorboard>=2.4.1

tqdm>=4.64.0
seaborn>=0.11.0
pandas

thop # FLOPs computation
thop>=0.1.1
6 changes: 1 addition & 5 deletions restapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ def predict():
if request.files.get("image"):
image_file = request.files["image"]
image_bytes = image_file.read()

img = Image.open(io.BytesIO(image_bytes))

results = model(img, size=640)
data = results.pandas().xyxy[0].to_json(orient="records")
return data
Expand All @@ -34,8 +32,6 @@ def predict():
parser.add_argument("--port", default=5000, type=int, help="port number")
args = parser.parse_args()

model = torch.hub.load(
"ultralytics/yolov5", "yolov5s", pretrained=True, force_reload=True
).autoshape() # force_reload = recache latest code
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True) # force_reload = recache latest code
model.eval()
app.run(host="0.0.0.0", port=args.port) # debug=True causes Restarting with stat
14 changes: 3 additions & 11 deletions webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,10 @@ def predict():

img_bytes = file.read()
img = Image.open(io.BytesIO(img_bytes))
results = model(img, size=640)

# for debugging
# data = results.pandas().xyxy[0].to_json(orient="records")
# return data
results = model([img])

results.render() # updates results.imgs with boxes and labels
for img in results.imgs:
img_base64 = Image.fromarray(img)
img_base64.save("static/image0.jpg", format="JPEG")
results.save(save_dir="static/")
return redirect("static/image0.jpg")

return render_template("index.html")
Expand All @@ -44,8 +38,6 @@ def predict():
parser.add_argument("--port", default=5000, type=int, help="port number")
args = parser.parse_args()

model = torch.hub.load(
"ultralytics/yolov5", "yolov5s", pretrained=True, force_reload=True, autoshape=True
) # force_reload = recache latest code
model = torch.hub.load('ultralytics/yolov5', 'yolov5s', pretrained=True) # force_reload = recache latest code
model.eval()
app.run(host="0.0.0.0", port=args.port) # debug=True causes Restarting with stat

0 comments on commit 27e8f91

Please sign in to comment.