Traffic b2 (#1345)

* add traffic convention

* hope this work

* no comment

* latest and gratest

* big gru model

* 1af55c7d-ee15-414a-9e98-a0cb08c3441f/75

* much later in training

* wrong temporal size

* converged

* fix lane changes
albatross
HaraldSchafer 2020-04-13 13:27:06 -07:00 committed by GitHub
parent fc10fe69bf
commit d3edc594ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 57 additions and 30 deletions

BIN
models/supercombo.dlc (Stored with Git LFS)

Binary file not shown.

BIN
models/supercombo.keras (Stored with Git LFS)

Binary file not shown.

View File

@ -205,8 +205,8 @@ int main(int argc, char **argv) {
double mt1 = 0, mt2 = 0; double mt1 = 0, mt2 = 0;
if (run_model_this_iter) { if (run_model_this_iter) {
float vec_desire[DESIRE_SIZE] = {0}; float vec_desire[DESIRE_LEN] = {0};
if (desire >= 0 && desire < DESIRE_SIZE) { if (desire >= 0 && desire < DESIRE_LEN) {
vec_desire[desire] = 1.0; vec_desire[desire] = 1.0;
} }
@ -219,7 +219,7 @@ int main(int argc, char **argv) {
ModelDataRaw model_buf = ModelDataRaw model_buf =
model_eval_frame(&model, q, yuv_cl, buf_info.width, buf_info.height, model_eval_frame(&model, q, yuv_cl, buf_info.width, buf_info.height,
model_transform, NULL, vec_desire); model_transform, NULL, vec_desire, NULL);
mt2 = millis_since_boot(); mt2 = millis_since_boot();
model_publish(model_sock, extra.frame_id, model_buf, extra.timestamp_eof); model_publish(model_sock, extra.frame_id, model_buf, extra.timestamp_eof);

View File

@ -18,7 +18,7 @@
#define POSE_IDX META_IDX + OTHER_META_SIZE + DESIRE_PRED_SIZE #define POSE_IDX META_IDX + OTHER_META_SIZE + DESIRE_PRED_SIZE
#define OUTPUT_SIZE POSE_IDX + POSE_SIZE #define OUTPUT_SIZE POSE_IDX + POSE_SIZE
#ifdef TEMPORAL #ifdef TEMPORAL
#define TEMPORAL_SIZE 512 #define TEMPORAL_SIZE 1024
#else #else
#define TEMPORAL_SIZE 0 #define TEMPORAL_SIZE 0
#endif #endif
@ -42,11 +42,17 @@ void model_init(ModelState* s, cl_device_id device_id, cl_context context, int t
#endif #endif
#ifdef DESIRE #ifdef DESIRE
s->desire = (float*)malloc(DESIRE_SIZE * sizeof(float)); s->prev_desire = (float*)malloc(DESIRE_LEN * sizeof(float));
for (int i = 0; i < DESIRE_SIZE; i++) s->desire[i] = 0.0; for (int i = 0; i < DESIRE_LEN; i++) s->prev_desire[i] = 0.0;
s->pulse_desire = (float*)malloc(DESIRE_SIZE * sizeof(float)); s->pulse_desire = (float*)malloc(DESIRE_LEN * sizeof(float));
for (int i = 0; i < DESIRE_SIZE; i++) s->pulse_desire[i] = 0.0; for (int i = 0; i < DESIRE_LEN; i++) s->pulse_desire[i] = 0.0;
s->m->addDesire(s->pulse_desire, DESIRE_SIZE); s->m->addDesire(s->pulse_desire, DESIRE_LEN);
#endif
#ifdef TRAFFIC_CONVENTION
s->traffic_convention = (float*)malloc(TRAFFIC_CONVENTION_LEN * sizeof(float));
for (int i = 0; i < TRAFFIC_CONVENTION_LEN; i++) s->traffic_convention[i] = 0.0;
s->m->addTrafficConvention(s->traffic_convention, TRAFFIC_CONVENTION_LEN);
#endif #endif
// Build Vandermonde matrix // Build Vandermonde matrix
@ -61,18 +67,27 @@ void model_init(ModelState* s, cl_device_id device_id, cl_context context, int t
ModelDataRaw model_eval_frame(ModelState* s, cl_command_queue q, ModelDataRaw model_eval_frame(ModelState* s, cl_command_queue q,
cl_mem yuv_cl, int width, int height, cl_mem yuv_cl, int width, int height,
mat3 transform, void* sock, float *desire_in) { mat3 transform, void* sock,
float *desire_in, float *traffic_convention_in) {
#ifdef DESIRE #ifdef DESIRE
if (desire_in != NULL) { if (desire_in != NULL) {
for (int i = 0; i < DESIRE_SIZE; i++) { for (int i = 0; i < DESIRE_LEN; i++) {
// Model decides when action is completed // Model decides when action is completed
// so desire input is just a pulse triggered on rising edge // so desire input is just a pulse triggered on rising edge
if (desire_in[i] - s->desire[i] == 1) { if (desire_in[i] - s->prev_desire[i] > .99) {
s->pulse_desire[i] = desire_in[i]; s->pulse_desire[i] = desire_in[i];
} else { } else {
s->pulse_desire[i] = 0.0; s->pulse_desire[i] = 0.0;
} }
s->desire[i] = desire_in[i]; s->prev_desire[i] = desire_in[i];
}
}
#endif
#ifdef TRAFFIC_CONVENTION
if (traffic_convention_in != NULL) {
for (int i = 0; i < TRAFFIC_CONVENTION_LEN; i++) {
s->traffic_convention[i] = traffic_convention_in[i];
} }
} }
#endif #endif

View File

@ -4,10 +4,7 @@
// gate this here // gate this here
#define TEMPORAL #define TEMPORAL
#define DESIRE #define DESIRE
#define TRAFFIC_CONVENTION
#ifdef DESIRE
#define DESIRE_SIZE 8
#endif
#ifdef QCOM #ifdef QCOM
#include <eigen3/Eigen/Dense> #include <eigen3/Eigen/Dense>
@ -35,6 +32,7 @@
#define POLYFIT_DEGREE 4 #define POLYFIT_DEGREE 4
#define SPEED_PERCENTILES 10 #define SPEED_PERCENTILES 10
#define DESIRE_LEN 8 #define DESIRE_LEN 8
#define TRAFFIC_CONVENTION_LEN 2
#define DESIRE_PRED_SIZE 32 #define DESIRE_PRED_SIZE 32
#define OTHER_META_SIZE 4 #define OTHER_META_SIZE 4
#define LEAD_MDN_N 5 // probs for 5 groups #define LEAD_MDN_N 5 // probs for 5 groups
@ -64,16 +62,19 @@ typedef struct ModelState {
float *input_frames; float *input_frames;
RunModel *m; RunModel *m;
#ifdef DESIRE #ifdef DESIRE
float *desire; float *prev_desire;
float *pulse_desire; float *pulse_desire;
#endif #endif
#ifdef TRAFFIC_CONVENTION
float *traffic_convention;
#endif
} ModelState; } ModelState;
void model_init(ModelState* s, cl_device_id device_id, void model_init(ModelState* s, cl_device_id device_id,
cl_context context, int temporal); cl_context context, int temporal);
ModelDataRaw model_eval_frame(ModelState* s, cl_command_queue q, ModelDataRaw model_eval_frame(ModelState* s, cl_command_queue q,
cl_mem yuv_cl, int width, int height, cl_mem yuv_cl, int width, int height,
mat3 transform, void* sock, float *desire_in); mat3 transform, void* sock, float *desire_in, float *traffic_convention_in);
void model_free(ModelState* s); void model_free(ModelState* s);
void poly_fit(float *in_pts, float *in_stds, float *out); void poly_fit(float *in_pts, float *in_stds, float *out);

View File

@ -5,6 +5,7 @@ class RunModel {
public: public:
virtual void addRecurrent(float *state, int state_size) {} virtual void addRecurrent(float *state, int state_size) {}
virtual void addDesire(float *state, int state_size) {} virtual void addDesire(float *state, int state_size) {}
virtual void addTrafficConvention(float *state, int state_size) {}
virtual void execute(float *net_input_buf, int buf_size) {} virtual void execute(float *net_input_buf, int buf_size) {}
}; };

View File

@ -94,7 +94,11 @@ SNPEModel::SNPEModel(const char *path, float *output, size_t output_size, int ru
} }
void SNPEModel::addRecurrent(float *state, int state_size) { void SNPEModel::addRecurrent(float *state, int state_size) {
recurrentBuffer = this->addExtra(state, state_size, 2); recurrentBuffer = this->addExtra(state, state_size, 3);
}
void SNPEModel::addTrafficConvention(float *state, int state_size) {
trafficConventionBuffer = this->addExtra(state, state_size, 2);
} }
void SNPEModel::addDesire(float *state, int state_size) { void SNPEModel::addDesire(float *state, int state_size) {

View File

@ -24,6 +24,7 @@ public:
if (model_data) free(model_data); if (model_data) free(model_data);
} }
void addRecurrent(float *state, int state_size); void addRecurrent(float *state, int state_size);
void addTrafficConvention(float *state, int state_size);
void addDesire(float *state, int state_size); void addDesire(float *state, int state_size);
void execute(float *net_input_buf, int buf_size); void execute(float *net_input_buf, int buf_size);
private: private:
@ -44,6 +45,7 @@ private:
// recurrent and desire // recurrent and desire
std::unique_ptr<zdl::DlSystem::IUserBuffer> addExtra(float *state, int state_size, int idx); std::unique_ptr<zdl::DlSystem::IUserBuffer> addExtra(float *state, int state_size, int idx);
std::unique_ptr<zdl::DlSystem::IUserBuffer> recurrentBuffer; std::unique_ptr<zdl::DlSystem::IUserBuffer> recurrentBuffer;
std::unique_ptr<zdl::DlSystem::IUserBuffer> trafficConventionBuffer;
std::unique_ptr<zdl::DlSystem::IUserBuffer> desireBuffer; std::unique_ptr<zdl::DlSystem::IUserBuffer> desireBuffer;
}; };

View File

@ -88,6 +88,11 @@ void TFModel::addDesire(float *state, int state_size) {
desire_state_size = state_size; desire_state_size = state_size;
} }
void TFModel::addTrafficConvention(float *state, int state_size) {
traffic_convention_input_buf = state;
traffic_convention_size = state_size;
}
void TFModel::execute(float *net_input_buf, int buf_size) { void TFModel::execute(float *net_input_buf, int buf_size) {
// order must be this // order must be this
pwrite(net_input_buf, buf_size); pwrite(net_input_buf, buf_size);

View File

@ -12,6 +12,7 @@ public:
~TFModel(); ~TFModel();
void addRecurrent(float *state, int state_size); void addRecurrent(float *state, int state_size);
void addDesire(float *state, int state_size); void addDesire(float *state, int state_size);
void addTrafficConvention(float *state, int state_size);
void execute(float *net_input_buf, int buf_size); void execute(float *net_input_buf, int buf_size);
private: private:
int proc_pid; int proc_pid;
@ -23,6 +24,8 @@ private:
int rnn_state_size; int rnn_state_size;
float *desire_input_buf = NULL; float *desire_input_buf = NULL;
int desire_state_size; int desire_state_size;
float *traffic_convention_input_buf = NULL;
int traffic_convention_size;
// pipe to communicate to keras subprocess // pipe to communicate to keras subprocess
void pread(float *buf, int size); void pread(float *buf, int size);

View File

@ -9,9 +9,7 @@ __kernel void loadys(__global uchar8 const * const Y,
const int ox = ois % TRANSFORMED_WIDTH; const int ox = ois % TRANSFORMED_WIDTH;
const uchar8 ys = Y[gid]; const uchar8 ys = Y[gid];
const float8 ysf = convert_float8(ys);
// y = (x - 128) / 128
const float8 ysf = (convert_float8(ys) - 128.f) * 0.0078125f;
// 02 // 02
// 13 // 13
@ -36,8 +34,6 @@ __kernel void loaduv(__global uchar8 const * const in,
{ {
const int gid = get_global_id(0); const int gid = get_global_id(0);
const uchar8 inv = in[gid]; const uchar8 inv = in[gid];
const float8 outv = convert_float8(inv);
// y = (x - 128) / 128
const float8 outv = (convert_float8(inv) - 128.f) * 0.0078125f;
out[gid + out_offset / 8] = outv; out[gid + out_offset / 8] = outv;
} }