Skip to content

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)


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



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)


while True:
wrapper.run()
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

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.

3 participants