-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Emergent Object Detection/Classification Model.v1 #56
Changes from 6 commits
c4839e1
8e61358
1d388ae
52a05cc
24d4b21
e475428
9e9d0ba
ad94558
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import torch | ||
|
||
# You may have to install: | ||
# pandas | ||
# torchvision | ||
# tqdm | ||
# seaborn | ||
|
||
MODEL_PATH = "vision/emergent_object/best.pt" | ||
Comment on lines
+10
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this constant is only used in |
||
|
||
|
||
# Function to do detection / classification | ||
def emergent_object_detection(image, model): | ||
# Convert to RGB | ||
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Type hint for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of assigning the result of |
||
|
||
# Run the model on the image. Both a file path and a numpy image work, but | ||
# we want to use a numpy image | ||
results = model(image) | ||
|
||
# Retrieve the output from the model | ||
output = results.pandas().xyxy[0] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. type hints for results and output There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
return output | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function needs:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the docstring for this function, make sure to describe what kind of output one should expect from it. |
||
|
||
|
||
# Load the model from the file | ||
def emergent_object_model(): | ||
model = torch.hub.load("ultralytics/yolov5", "custom", path=MODEL_PATH) | ||
return model | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function needs:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need type hint for |
||
|
||
|
||
if __name__ == "__main__": | ||
import cv2 | ||
|
||
Comment on lines
+65
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
image_path = "vision/emergent_object/people.png" | ||
|
||
Comment on lines
+67
to
+68
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could make this into a command line argument |
||
image = cv2.imread(image_path) | ||
|
||
# Create model | ||
model = emergent_object_model() | ||
|
||
# Use model for detection / classification | ||
output = emergent_object_detection(image, model) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Type hints for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
# Convert the Pandas Dataframe to a dictionary - this will be necessary and | ||
# should eventually be done in `emergent_object_detection()` | ||
output_dict = output.to_dict("index") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should do what this comment says about the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. type hint for |
||
|
||
# Draw the bounding boxes to the original image | ||
for row in output_dict.values(): | ||
Comment on lines
+81
to
+82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Type hint for
|
||
# Get the output ranges | ||
top_left = (int(row["xmin"]), int(row["ymin"])) | ||
bottom_right = (int(row["xmax"]), int(row["ymax"])) | ||
Comment on lines
+83
to
+85
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. type hints for these two variables |
||
|
||
# Draw the bounding box | ||
cv2.rectangle(image, top_left, bottom_right, (255, 0, 0), 4) | ||
|
||
# Display the image | ||
cv2.imshow("", image) | ||
Comment on lines
+90
to
+91
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might want something like "Emergent Object" instead of an empty string for the title. |
||
cv2.waitKey(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dependencies should all be taken care of by #58 if you run in a poetry shell. These comments can be removed.