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.
thedavidchu
left a comment
There was a problem hiding this comment.
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.
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: |
There was a problem hiding this comment.
Added typing. Okay in Python 3 only
|
|
||
|
|
||
| def get_input(frame): | ||
| frame = cv2.resize(frame,(1280,720),interpolation=cv2.INTER_AREA) |
There was a problem hiding this comment.
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.
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() No newline at end of file | ||
| try: |
There was a problem hiding this comment.
REAL CHANGE
Wrapped Python3 code in try-except
There was a problem hiding this comment.
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.
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: |
There was a problem hiding this comment.
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.
@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)