Skip to content
Snippets Groups Projects
Commit 168ae8c4 authored by akhot2's avatar akhot2
Browse files

Update transfer/transfer.py

parent 67a0d951
No related branches found
No related tags found
1 merge request!11Update transfer/transfer.py
...@@ -35,6 +35,11 @@ for file in os.listdir(dir): ...@@ -35,6 +35,11 @@ for file in os.listdir(dir):
shutil.move(src_path, dest_path) shutil.move(src_path, dest_path)
save_paths.append(dest_path) save_paths.append(dest_path)
#load model
model_path = '../yolov5_model/runs/train/many_small_bugs_final/weights/best.pt'
model = torch.hub.load('ultralytics/yolov5', 'custom', model_path)
model.eval()
# create output csv # create output csv
csv = 'Image Path, Location, Number of Beetles\n' csv = 'Image Path, Location, Number of Beetles\n'
for path in save_paths: for path in save_paths:
...@@ -47,13 +52,11 @@ for path in save_paths: ...@@ -47,13 +52,11 @@ for path in save_paths:
warped_rgb = crop(image) warped_rgb = crop(image)
# run model # run model
model_path = '' result = model(warped_rgb)
model = torch.hub.load(model_path) num_beetles = results.pandas().xyxy[0].shape[0]
result = model(path)
# update csv # update csv
csv += f'{path},{trap_label},{result}\n' csv += f'{path},{trap_label},{num_beetles}\n'
csv_path = os.path.join(save_dir, 'output.csv') csv_path = os.path.join(save_dir, 'output.csv')
with open(csv_path, 'a') as csvfile: with open(csv_path, 'a') as csvfile:
csvfile.write(csv) csvfile.write(csv)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment