|
|
@ -17,10 +17,6 @@ constexpr int OTHER_META_SIZE = 32; |
|
|
|
constexpr int NUM_META_INTERVALS = 5; |
|
|
|
constexpr int NUM_META_INTERVALS = 5; |
|
|
|
constexpr int META_STRIDE = 6; |
|
|
|
constexpr int META_STRIDE = 6; |
|
|
|
|
|
|
|
|
|
|
|
constexpr int MODEL_WIDTH = 512; |
|
|
|
|
|
|
|
constexpr int MODEL_HEIGHT = 256; |
|
|
|
|
|
|
|
constexpr int MODEL_FRAME_SIZE = MODEL_WIDTH * MODEL_HEIGHT * 3 / 2; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constexpr int PLAN_MHP_N = 5; |
|
|
|
constexpr int PLAN_MHP_N = 5; |
|
|
|
constexpr int PLAN_MHP_COLUMNS = 15; |
|
|
|
constexpr int PLAN_MHP_COLUMNS = 15; |
|
|
|
constexpr int PLAN_MHP_VALS = 15*33; |
|
|
|
constexpr int PLAN_MHP_VALS = 15*33; |
|
|
@ -60,8 +56,7 @@ float prev_brake_3ms2_probs[3] = {0,0,0}; |
|
|
|
// #define DUMP_YUV
|
|
|
|
// #define DUMP_YUV
|
|
|
|
|
|
|
|
|
|
|
|
void model_init(ModelState* s, cl_device_id device_id, cl_context context) { |
|
|
|
void model_init(ModelState* s, cl_device_id device_id, cl_context context) { |
|
|
|
frame_init(&s->frame, MODEL_WIDTH, MODEL_HEIGHT, device_id, context); |
|
|
|
s->frame = new ModelFrame(device_id, context); |
|
|
|
s->input_frames = std::make_unique<float[]>(MODEL_FRAME_SIZE * 2); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constexpr int output_size = OUTPUT_SIZE + TEMPORAL_SIZE; |
|
|
|
constexpr int output_size = OUTPUT_SIZE + TEMPORAL_SIZE; |
|
|
|
s->output.resize(output_size); |
|
|
|
s->output.resize(output_size); |
|
|
@ -85,8 +80,6 @@ void model_init(ModelState* s, cl_device_id device_id, cl_context context) { |
|
|
|
s->traffic_convention[idx] = 1.0; |
|
|
|
s->traffic_convention[idx] = 1.0; |
|
|
|
s->m->addTrafficConvention(s->traffic_convention, TRAFFIC_CONVENTION_LEN); |
|
|
|
s->m->addTrafficConvention(s->traffic_convention, TRAFFIC_CONVENTION_LEN); |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
s->q = CL_CHECK_ERR(clCreateCommandQueue(context, device_id, 0, &err)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
ModelDataRaw model_eval_frame(ModelState* s, cl_mem yuv_cl, int width, int height, |
|
|
|
ModelDataRaw model_eval_frame(ModelState* s, cl_mem yuv_cl, int width, int height, |
|
|
@ -108,19 +101,8 @@ ModelDataRaw model_eval_frame(ModelState* s, cl_mem yuv_cl, int width, int heigh |
|
|
|
|
|
|
|
|
|
|
|
//for (int i = 0; i < OUTPUT_SIZE + TEMPORAL_SIZE; i++) { printf("%f ", s->output[i]); } printf("\n");
|
|
|
|
//for (int i = 0; i < OUTPUT_SIZE + TEMPORAL_SIZE; i++) { printf("%f ", s->output[i]); } printf("\n");
|
|
|
|
|
|
|
|
|
|
|
|
float *new_frame_buf = frame_prepare(&s->frame, s->q, yuv_cl, width, height, transform); |
|
|
|
auto net_input_buf = s->frame->prepare(yuv_cl, width, height, transform); |
|
|
|
memmove(&s->input_frames[0], &s->input_frames[MODEL_FRAME_SIZE], sizeof(float)*MODEL_FRAME_SIZE); |
|
|
|
s->m->execute(net_input_buf, s->frame->buf_size); |
|
|
|
memmove(&s->input_frames[MODEL_FRAME_SIZE], new_frame_buf, sizeof(float)*MODEL_FRAME_SIZE); |
|
|
|
|
|
|
|
s->m->execute(&s->input_frames[0], MODEL_FRAME_SIZE*2); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef DUMP_YUV |
|
|
|
|
|
|
|
FILE *dump_yuv_file = fopen("/sdcard/dump.yuv", "wb"); |
|
|
|
|
|
|
|
fwrite(new_frame_buf, MODEL_HEIGHT*MODEL_WIDTH*3/2, sizeof(float), dump_yuv_file); |
|
|
|
|
|
|
|
fclose(dump_yuv_file); |
|
|
|
|
|
|
|
assert(1==2); |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
clEnqueueUnmapMemObject(s->q, s->frame.net_input, (void*)new_frame_buf, 0, NULL, NULL); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// net outputs
|
|
|
|
// net outputs
|
|
|
|
ModelDataRaw net_outputs; |
|
|
|
ModelDataRaw net_outputs; |
|
|
@ -136,8 +118,7 @@ ModelDataRaw model_eval_frame(ModelState* s, cl_mem yuv_cl, int width, int heigh |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void model_free(ModelState* s) { |
|
|
|
void model_free(ModelState* s) { |
|
|
|
frame_free(&s->frame); |
|
|
|
delete s->frame; |
|
|
|
CL_CHECK(clReleaseCommandQueue(s->q)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static const float *get_best_data(const float *data, int size, int group_size, int offset) { |
|
|
|
static const float *get_best_data(const float *data, int size, int group_size, int offset) { |
|
|
@ -203,8 +184,8 @@ void fill_meta(cereal::ModelDataV2::MetaData::Builder meta, const float *meta_da |
|
|
|
fill_sigmoid(&meta_data[DESIRE_LEN+5], brake_4ms2_sigmoid, NUM_META_INTERVALS, META_STRIDE); |
|
|
|
fill_sigmoid(&meta_data[DESIRE_LEN+5], brake_4ms2_sigmoid, NUM_META_INTERVALS, META_STRIDE); |
|
|
|
fill_sigmoid(&meta_data[DESIRE_LEN+6], brake_5ms2_sigmoid, NUM_META_INTERVALS, META_STRIDE); |
|
|
|
fill_sigmoid(&meta_data[DESIRE_LEN+6], brake_5ms2_sigmoid, NUM_META_INTERVALS, META_STRIDE); |
|
|
|
|
|
|
|
|
|
|
|
memmove(prev_brake_5ms2_probs, &prev_brake_5ms2_probs[1], 4*sizeof(float)); |
|
|
|
std::memmove(prev_brake_5ms2_probs, &prev_brake_5ms2_probs[1], 4*sizeof(float)); |
|
|
|
memmove(prev_brake_3ms2_probs, &prev_brake_3ms2_probs[1], 2*sizeof(float)); |
|
|
|
std::memmove(prev_brake_3ms2_probs, &prev_brake_3ms2_probs[1], 2*sizeof(float)); |
|
|
|
prev_brake_5ms2_probs[4] = brake_5ms2_sigmoid[0]; |
|
|
|
prev_brake_5ms2_probs[4] = brake_5ms2_sigmoid[0]; |
|
|
|
prev_brake_3ms2_probs[2] = brake_3ms2_sigmoid[0]; |
|
|
|
prev_brake_3ms2_probs[2] = brake_3ms2_sigmoid[0]; |
|
|
|
|
|
|
|
|
|
|
|