Skip to content
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

Closed
wants to merge 8 commits into from

Conversation

noahbodine
Copy link
Contributor

Closes #12
Model to detect / classify emergent objects & pretrained weights for the model.

@noahbodine noahbodine added vision Relating to image or visual stream handling and processing emergent object Task related to the emergent object labels Feb 22, 2023
@noahbodine noahbodine self-assigned this Feb 22, 2023
@noahbodine noahbodine linked an issue Feb 22, 2023 that may be closed by this pull request
Copy link
Member

@fallscameron01 fallscameron01 left a 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 like emergent_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

vision/emergent_object/emergent_object.py Outdated Show resolved Hide resolved
vision/emergent_object/emergent_object.py Outdated Show resolved Hide resolved
vision/emergent_object/emergent_object.py Outdated Show resolved Hide resolved
vision/emergent_object/emergent_object.py Outdated Show resolved Hide resolved
vision/emergent_object/emergent_object.py Outdated Show resolved Hide resolved
vision/emergent_object/emergent_object.py Outdated Show resolved Hide resolved
vision/emergent_object/emergent_object.py Outdated Show resolved Hide resolved
vision/emergent_object/emergent_object.py Outdated Show resolved Hide resolved
vision/emergent_object/emergent_object.py Outdated Show resolved Hide resolved
vision/emergent_object/emergent_object.py Outdated Show resolved Hide resolved
@fallscameron01 fallscameron01 added the good first issue Good for newcomers label Mar 2, 2023
@fallscameron01
Copy link
Member

Good first issue for someone to take up the fixes for this PR

@eblake003
Copy link
Contributor

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.

@fallscameron01 fallscameron01 self-requested a review March 6, 2023 05:09
Copy link
Member

@fallscameron01 fallscameron01 left a 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.

Comment on lines +3 to +7
# You may have to install:
# pandas
# torchvision
# tqdm
# seaborn
Copy link
Member

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.

Comment on lines +8 to +9

MODEL_PATH = "vision/emergent_object/best.pt"
Copy link
Member

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.

Comment on lines 12 to 24
# 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
Copy link
Member

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

Comment on lines 14 to 15
# Convert to RGB
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
Copy link
Member

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

Comment on lines 19 to 22
results = model(image)

# Retrieve the output from the model
output = results.pandas().xyxy[0]
Copy link
Member

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

Comment on lines 46 to 48
# 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")
Copy link
Member

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

Comment on lines +50 to +51
# Draw the bounding boxes to the original image
for row in output_dict.values():
Copy link
Member

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 ...

Comment on lines +52 to +54
# Get the output ranges
top_left = (int(row["xmin"]), int(row["ymin"]))
bottom_right = (int(row["xmax"]), int(row["ymax"]))
Copy link
Member

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

Comment on lines +59 to +60
# Display the image
cv2.imshow("", image)
Copy link
Member

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.

Comment on lines 12 to 24
# 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
Copy link
Member

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.

@fallscameron01
Copy link
Member

Opened new PR #96 because something was wrong with this branch that caused a split.

@fallscameron01 fallscameron01 deleted the Feature/EmergentObject branch March 16, 2023 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
emergent object Task related to the emergent object good first issue Good for newcomers vision Relating to image or visual stream handling and processing
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Classify the Emergent Object Detect the Emergent Object
3 participants