forked from jeankalud/openpilot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
955 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
Import('env', 'arch', 'messaging', 'common', 'visionipc') | ||
Import('env', 'arch', 'is_tbp', 'messaging', 'common', 'visionipc') | ||
|
||
src = ['loggerd.cc', 'logger.cc'] | ||
libs = ['zmq', 'czmq', 'capnp', 'kj', 'z', | ||
'avformat', 'avcodec', 'swscale', 'avutil', | ||
'yuv', 'bz2', common, 'json', messaging, visionipc] | ||
|
||
if arch == "aarch64": | ||
src += ['encoder.c', 'raw_logger.cc'] | ||
libs += ['OmxVenc', 'OmxCore', 'cutils'] | ||
if not is_tbp: | ||
src += ['encoder.c', 'raw_logger.cc'] | ||
libs += ['OmxVenc', 'OmxCore', 'cutils'] | ||
|
||
env.Program(src, LIBS=libs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#include "tfmodel.h" | ||
#include <stdio.h> | ||
#include <string> | ||
#include <string.h> | ||
#include <signal.h> | ||
#include <unistd.h> | ||
#include <stdlib.h> | ||
#include <stdexcept> | ||
#include "common/util.h" | ||
#include "common/utilpp.h" | ||
#include "common/swaglog.h" | ||
#include <cassert> | ||
|
||
|
||
TFModel::TFModel(const char *path, float *_output, size_t _output_size, int runtime) { | ||
output = _output; | ||
output_size = _output_size; | ||
|
||
char tmp[1024]; | ||
strncpy(tmp, path, sizeof(tmp)); | ||
strstr(tmp, ".dlc")[0] = '\0'; | ||
strcat(tmp, ".keras"); | ||
LOGD("loading model %s", tmp); | ||
|
||
assert(pipe(pipein) == 0); | ||
assert(pipe(pipeout) == 0); | ||
|
||
std::string exe_dir = util::dir_name(util::readlink("/proc/self/exe")); | ||
std::string keras_runner = exe_dir + "/runners/keras_runner.py"; | ||
|
||
proc_pid = fork(); | ||
if (proc_pid == 0) { | ||
LOGD("spawning keras process %s", keras_runner.c_str()); | ||
char *argv[] = {(char*)keras_runner.c_str(), tmp, NULL}; | ||
dup2(pipein[0], 0); | ||
dup2(pipeout[1], 1); | ||
close(pipein[0]); | ||
close(pipein[1]); | ||
close(pipeout[0]); | ||
close(pipeout[1]); | ||
execvp(keras_runner.c_str(), argv); | ||
} | ||
|
||
// parent | ||
close(pipein[0]); | ||
close(pipeout[1]); | ||
} | ||
|
||
TFModel::~TFModel() { | ||
close(pipein[1]); | ||
close(pipeout[0]); | ||
kill(proc_pid, SIGTERM); | ||
} | ||
|
||
void TFModel::pwrite(float *buf, int size) { | ||
char *cbuf = (char *)buf; | ||
int tw = size*sizeof(float); | ||
while (tw > 0) { | ||
int err = write(pipein[1], cbuf, tw); | ||
//printf("host write %d\n", err); | ||
assert(err >= 0); | ||
cbuf += err; | ||
tw -= err; | ||
} | ||
//printf("host write done\n"); | ||
} | ||
|
||
void TFModel::pread(float *buf, int size) { | ||
char *cbuf = (char *)buf; | ||
int tr = size*sizeof(float); | ||
while (tr > 0) { | ||
int err = read(pipeout[0], cbuf, tr); | ||
//printf("host read %d/%d\n", err, tr); | ||
assert(err >= 0); | ||
cbuf += err; | ||
tr -= err; | ||
} | ||
//printf("host read done\n"); | ||
} | ||
|
||
void TFModel::addRecurrent(float *state, int state_size) { | ||
rnn_input_buf = state; | ||
rnn_state_size = state_size; | ||
} | ||
|
||
void TFModel::addDesire(float *state, int state_size) { | ||
desire_input_buf = state; | ||
desire_state_size = state_size; | ||
} | ||
|
||
void TFModel::execute(float *net_input_buf, int buf_size) { | ||
// order must be this | ||
pwrite(net_input_buf, buf_size); | ||
pwrite(desire_input_buf, desire_state_size); | ||
pwrite(rnn_input_buf, rnn_state_size); | ||
pread(output, output_size); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#ifndef TFMODEL_H | ||
#define TFMODEL_H | ||
|
||
#include <stdlib.h> | ||
#include "runmodel.h" | ||
|
||
struct TFState; | ||
|
||
class TFModel : public RunModel { | ||
public: | ||
TFModel(const char *path, float *output, size_t output_size, int runtime); | ||
~TFModel(); | ||
void addRecurrent(float *state, int state_size); | ||
void addDesire(float *state, int state_size); | ||
void execute(float *net_input_buf, int buf_size); | ||
private: | ||
int proc_pid; | ||
|
||
float *output; | ||
size_t output_size; | ||
|
||
float *rnn_input_buf = NULL; | ||
int rnn_state_size; | ||
float *desire_input_buf = NULL; | ||
int desire_state_size; | ||
|
||
// pipe to communicate to keras subprocess | ||
void pread(float *buf, int size); | ||
void pwrite(float *buf, int size); | ||
int pipein[2]; | ||
int pipeout[2]; | ||
}; | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#!/usr/bin/env python3.7 | ||
import os | ||
import json | ||
|
||
|
Oops, something went wrong.