Prerotate dmonitoringmodeld input (#2606)
* not tested, but something like this
* more like this
* dl and ur may still be flipped
* they were flipped
* Revert "they were flipped"
This reverts commit fbd477bb44
.
Co-authored-by: Comma Device <device@comma.ai>
This commit is contained in:
parent
238751e784
commit
327aa123f4
|
@ -114,6 +114,21 @@ DMonitoringResult dmonitoring_eval_frame(DMonitoringModelState* s, void* stream_
|
|||
resized_width, resized_height,
|
||||
mode);
|
||||
|
||||
// prerotate to be cache aware
|
||||
uint8_t *resized_buf_rot = get_buffer(s->resized_buf_rot, resized_width*resized_height*3/2);
|
||||
uint8_t *resized_y_buf_rot = resized_buf_rot;
|
||||
uint8_t *resized_u_buf_rot = resized_y_buf_rot + (resized_width * resized_height);
|
||||
uint8_t *resized_v_buf_rot = resized_u_buf_rot + ((resized_width/2) * (resized_height/2));
|
||||
|
||||
libyuv::I420Rotate(resized_y_buf, resized_width,
|
||||
resized_u_buf, resized_width/2,
|
||||
resized_v_buf, resized_width/2,
|
||||
resized_y_buf_rot, resized_height,
|
||||
resized_u_buf_rot, resized_height/2,
|
||||
resized_v_buf_rot, resized_height/2,
|
||||
// negative height causes a vertical flip to match previous
|
||||
resized_width, -resized_height, libyuv::kRotate90);
|
||||
|
||||
int yuv_buf_len = (MODEL_WIDTH/2) * (MODEL_HEIGHT/2) * 6; // Y|u|v -> y|y|y|y|u|v
|
||||
float *net_input_buf = get_buffer(s->net_input_buf, yuv_buf_len);
|
||||
// one shot conversion, O(n) anyway
|
||||
|
@ -121,17 +136,17 @@ DMonitoringResult dmonitoring_eval_frame(DMonitoringModelState* s, void* stream_
|
|||
for (int c = 0; c < MODEL_WIDTH/2; c++) {
|
||||
for (int r = 0; r < MODEL_HEIGHT/2; r++) {
|
||||
// Y_ul
|
||||
net_input_buf[(c*MODEL_HEIGHT/2) + r] = input_lambda(resized_buf[(2*r*resized_width) + (2*c)]);
|
||||
// Y_ur
|
||||
net_input_buf[(c*MODEL_HEIGHT/2) + r + (2*(MODEL_WIDTH/2)*(MODEL_HEIGHT/2))] = input_lambda(resized_buf[(2*r*resized_width) + (2*c+1)]);
|
||||
net_input_buf[(c*MODEL_HEIGHT/2) + r + (0*(MODEL_WIDTH/2)*(MODEL_HEIGHT/2))] = input_lambda(resized_buf_rot[(2*r) + (2*c)*resized_height]);
|
||||
// Y_dl
|
||||
net_input_buf[(c*MODEL_HEIGHT/2) + r + ((MODEL_WIDTH/2)*(MODEL_HEIGHT/2))] = input_lambda(resized_buf[(2*r*resized_width+1) + (2*c)]);
|
||||
net_input_buf[(c*MODEL_HEIGHT/2) + r + (1*(MODEL_WIDTH/2)*(MODEL_HEIGHT/2))] = input_lambda(resized_buf_rot[(2*r+1) + (2*c)*resized_height]);
|
||||
// Y_ur
|
||||
net_input_buf[(c*MODEL_HEIGHT/2) + r + (2*(MODEL_WIDTH/2)*(MODEL_HEIGHT/2))] = input_lambda(resized_buf_rot[(2*r) + (2*c+1)*resized_height]);
|
||||
// Y_dr
|
||||
net_input_buf[(c*MODEL_HEIGHT/2) + r + (3*(MODEL_WIDTH/2)*(MODEL_HEIGHT/2))] = input_lambda(resized_buf[(2*r*resized_width+1) + (2*c+1)]);
|
||||
net_input_buf[(c*MODEL_HEIGHT/2) + r + (3*(MODEL_WIDTH/2)*(MODEL_HEIGHT/2))] = input_lambda(resized_buf_rot[(2*r+1) + (2*c+1)*resized_height]);
|
||||
// U
|
||||
net_input_buf[(c*MODEL_HEIGHT/2) + r + (4*(MODEL_WIDTH/2)*(MODEL_HEIGHT/2))] = input_lambda(resized_buf[(resized_width*resized_height) + (r*resized_width/2) + c]);
|
||||
net_input_buf[(c*MODEL_HEIGHT/2) + r + (4*(MODEL_WIDTH/2)*(MODEL_HEIGHT/2))] = input_lambda(resized_buf_rot[(resized_width*resized_height) + r + (c*resized_height/2)]);
|
||||
// V
|
||||
net_input_buf[(c*MODEL_HEIGHT/2) + r + (5*(MODEL_WIDTH/2)*(MODEL_HEIGHT/2))] = input_lambda(resized_buf[(resized_width*resized_height) + ((resized_width/2)*(resized_height/2)) + (r*resized_width/2) + c]);
|
||||
net_input_buf[(c*MODEL_HEIGHT/2) + r + (5*(MODEL_WIDTH/2)*(MODEL_HEIGHT/2))] = input_lambda(resized_buf_rot[(resized_width*resized_height) + ((resized_width/2)*(resized_height/2)) + r + (c*resized_height/2)]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -140,6 +155,10 @@ DMonitoringResult dmonitoring_eval_frame(DMonitoringModelState* s, void* stream_
|
|||
//fwrite(raw_buf, height*width*3/2, sizeof(uint8_t), dump_yuv_file);
|
||||
//fclose(dump_yuv_file);
|
||||
|
||||
// *** testing ***
|
||||
// idat = np.frombuffer(open("/tmp/inputdump.yuv", "rb").read(), np.float32).reshape(6, 160, 320)
|
||||
// imshow(cv2.cvtColor(tensor_to_frames(idat[None]/0.0078125+128)[0], cv2.COLOR_YUV2RGB_I420))
|
||||
|
||||
//FILE *dump_yuv_file2 = fopen("/tmp/inputdump.yuv", "wb");
|
||||
//fwrite(net_input_buf, MODEL_HEIGHT*MODEL_WIDTH*3/2, sizeof(float), dump_yuv_file2);
|
||||
//fclose(dump_yuv_file2);
|
||||
|
|
|
@ -29,6 +29,7 @@ typedef struct DMonitoringModelState {
|
|||
bool is_rhd;
|
||||
float output[OUTPUT_SIZE];
|
||||
std::vector<uint8_t> resized_buf;
|
||||
std::vector<uint8_t> resized_buf_rot;
|
||||
std::vector<uint8_t> cropped_buf;
|
||||
std::vector<uint8_t> premirror_cropped_buf;
|
||||
std::vector<float> net_input_buf;
|
||||
|
|
Loading…
Reference in a new issue