-
Notifications
You must be signed in to change notification settings - Fork 2
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
base: cv_integration
Are you sure you want to change the base?
Exception Handling #114
Conversation
thedavidchu
commented
Jun 2, 2022
- 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.
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.
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: |
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.
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: |
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.
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) |
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.
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) |
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.
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: |
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.
REAL CHANGE
Wrapped Python3 code in try-except
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.
Maybe add logging on exception?
self.pub.publish(msg) | ||
|
||
lanes = self._fromRedis("pothole_detection") | ||
if lanes is not None: |
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.
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: |
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.
real change
check for None
…ved numbers around to do stuff
|
||
# 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) |
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.
@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)