-
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
Conversation
for more information, see https://pre-commit.ci
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.
Need a few changes to make sure the code is up to repo standards. You can check out the comments below for specifics. In addition to those comments, a few more changes below:
- Might want to choose a better name for
best.pt
. Something likeemergent_model.pt
or weights or something - Make sure that your code is passing pre-commit checks for mypy and pylint. You can check how to install/use these in the
ReadMe.md
Good first issue for someone to take up the fixes for this PR |
I worked out how to use the model and the output and added some code demonstrating its use. Docstrings and proper typehinting still need to be added, but the functionality should be pretty much all there at this point. |
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.
Updated review to reflect @EnderDude67 's changes. Comments from old review may be out of date, so refer to this review first and foremost.
# You may have to install: | ||
# pandas | ||
# torchvision | ||
# tqdm | ||
# seaborn |
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.
|
||
MODEL_PATH = "vision/emergent_object/best.pt" |
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.
Since this constant is only used in emergent_object_model()
, constant MODEL_PATH
should be moved to that function.
# Function to do detection / classification | ||
def emergent_object_detection(image, model): | ||
# Convert to RGB | ||
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) | ||
|
||
# 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] | ||
|
||
return output |
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.
Function needs:
- docstring
- parameter types
- return type
# Convert to RGB | ||
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) |
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.
Type hint for image
should be Image
type alias from vision > common > constants.py
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 comment
The reason will be displayed to describe this comment to others. Learn more.
type hints for results and output
# 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 comment
The reason will be displayed to describe this comment to others. Learn more.
type hint for output_dict
# Draw the bounding boxes to the original image | ||
for row in output_dict.values(): |
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.
Type hint for row
. Loop variables are type hinted like this:
row: Type
for row ...
# Get the output ranges | ||
top_left = (int(row["xmin"]), int(row["ymin"])) | ||
bottom_right = (int(row["xmax"]), int(row["ymax"])) |
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.
type hints for these two variables
# Display the image | ||
cv2.imshow("", image) |
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.
Might want something like "Emergent Object" instead of an empty string for the title.
# Function to do detection / classification | ||
def emergent_object_detection(image, model): | ||
# Convert to RGB | ||
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) | ||
|
||
# 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] | ||
|
||
return output |
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.
For the docstring for this function, make sure to describe what kind of output one should expect from it.
Opened new PR #96 because something was wrong with this branch that caused a split. |
Closes #12
Model to detect / classify emergent objects & pretrained weights for the model.