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

Exception Handling #114

Open
wants to merge 3 commits into
base: cv_integration
Choose a base branch
from

Conversation

thedavidchu
Copy link
Contributor

  • Linted with Black (sorry... it's automatic and my brain is too fried to have turned it off)
  • Added error handling (both try-except and if-else clauses)
  • Optimized the preprocessing of lane detection a little bit.

…to have turned it off), added error handling (both try-except and if-else clauses), and optimized the preprocessing of lane detection a little bit.
Copy link
Contributor Author

@thedavidchu thedavidchu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-commented code is mainly just formatting stuff. Next year, ROS should have an automatic linter ;)


def run(self):
raw = self._fromRedisImg("zed/preprocessed")
if raw is not None:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First "real" change (moved logic to if-guard)


edges_mask_inv = cv2.bitwise_not(edges_mask)

return edges_mask, edges_mask_inv


def get_input(frame):
frame = cv2.resize(frame,(1280,720),interpolation=cv2.INTER_AREA)
def get_input(frame: np.ndarray) -> np.ndarray:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added typing. Okay in Python 3 only


edges_mask_inv = cv2.bitwise_not(edges_mask)

return edges_mask, edges_mask_inv


def get_input(frame):
frame = cv2.resize(frame,(1280,720),interpolation=cv2.INTER_AREA)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I deleted this because it makes the model do work on an unnecessarily large image

frame_copy = np.append(frame_copy,test_edges.reshape(test_edges.shape[0],test_edges.shape[1],1),axis=2)
frame_copy = np.append(frame_copy,test_edges_inv.reshape(test_edges_inv.shape[0],test_edges_inv.shape[1],1),axis=2)
frame_copy = cv2.resize(frame_copy,(330,180))
test_edges, test_edges_inv = find_edge_channel(frame_copy)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REAL CHANGE

I combined the np.append's into a single np.block. I also moved the resize to the top (I'm fairly sure the function that is called on frame_copy is shape agnostic)

try:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REAL CHANGE

Wrapped Python3 code in try-except

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add logging on exception?

self.pub.publish(msg)

lanes = self._fromRedis("pothole_detection")
if lanes is not None:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REAL CHANGE:
Wrapped in if-clause. If-guard didn't work because we want some sleeping logic at the end

self.r.sleep()

def _fromRedis(self, name):
"""Retrieve Numpy array from Redis key 'n'"""
encoded = self.redis.get(name)
if encoded is None:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

real change

check for None


# Is this the correct permutation? Maybe try it out
# Shapes go: (330, 180, 5) ----> (5, 330, 180) --ERROR??--> (1, 5, 180, 330)
input = (frame_copy / 255.0).transpose(2, 0, 1).reshape(1, 5, HEIGHT, WIDTH)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jason-Y000 please double-check the logic and see if it's a bug or I'm just tripping. I'm really confused rn ngl and my brain is about to turn off from utter exhaustion 😫 lol

I'm just worried that it is changing the shape in a bad way (transposing the 330 with the 180)

@thedavidchu thedavidchu requested a review from ghamr June 2, 2022 03:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants