Skip to content

Commit

Permalink
still troubleshooting
Browse files Browse the repository at this point in the history
  • Loading branch information
BogGyver authored and SippieCup committed Apr 18, 2020
1 parent c693e3b commit 40ec817
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 17 deletions.
Binary file modified models/dmonitoring_model.keras
Binary file not shown.
Binary file modified models/dmonitoring_model_q.dlc
Binary file not shown.
3 changes: 3 additions & 0 deletions models/supercombo.dlc
Git LFS file not shown
3 changes: 3 additions & 0 deletions models/supercombo.keras
Git LFS file not shown
2 changes: 1 addition & 1 deletion models/supercombo.model.keras

Large diffs are not rendered by default.

Binary file modified models/supercombo.weights.keras
Binary file not shown.
3 changes: 1 addition & 2 deletions selfdrive/camerad/cameras/camera_webcam.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ void open_gl_stream_def(CameraState * s, char* camera_id, int width, int height,
if (flip == 1) {
flip_command = "videoflip method=rotate-180 ! ";
}
//1.5 is a fixed factor that came from Comma implementation
sprintf(*strm_def,strm_template.c_str(),camera_id, width, height, s->fps, (int)(s->ci.frame_width*fx*1.5), (int)(s->ci.frame_height*fx*1.5), flip_command.c_str(), s->ci.frame_width, s->ci.frame_height);
sprintf(*strm_def,strm_template.c_str(),camera_id, width, height, s->fps, (int)(s->ci.frame_width*fx), (int)(s->ci.frame_height*fx), flip_command.c_str(), s->ci.frame_width, s->ci.frame_height);
printf(" GL Stream :[%s]\n",*strm_def);
}

Expand Down
2 changes: 1 addition & 1 deletion selfdrive/common/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ files = [


if is_tbp:
defines = {"CLU_NO_CACHE": None}
defines = {} #{"CLU_NO_CACHE": None}
files += [
'visionbuf_cl.c',
]
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/modeld/models/driving.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
// gate this here
#define TEMPORAL
#define DESIRE
#define TRAFFIC_CONVENTION

#ifdef QCOM
#define TRAFFIC_CONVENTION
#include <eigen3/Eigen/Dense>
#else
#include <Eigen/Dense>
Expand Down
41 changes: 30 additions & 11 deletions selfdrive/modeld/runners/keras_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,25 @@ def read(sz):
def write(d):
os.write(1, d.tobytes())

def run_loop(m):
def run_loop(m,name):
isize = m.inputs[0].shape[1]
osize = m.outputs[0].shape[1]
int
print("ready to run keras model %d -> %d" % (isize, osize), file=sys.stderr)
cnt = 0
while 1:
if name == "supercombo":
cnt = (cnt + 1 ) % 100
if (cnt % 20 == 1):
print("Processing frame %d " % cnt, file=sys.stderr)
# check parent process, if ppid is 1, then modeld is no longer running and the runner should exit.
if os.getppid() == 1:
break
print("exiting due to Parent PID", file=sys.stderr)
#break
idata = read(isize).reshape((1, isize))
ret = m.predict_on_batch(idata)
if (cnt % 20 == 1):
print(ret, file=sys.stderr)
write(ret)

if __name__ == "__main__":
Expand All @@ -42,16 +51,26 @@ def run_loop(m):
gpus = tf.config.experimental.list_physical_devices('GPU')
model_path = Path(sys.argv[1]).parents[0]
name = Path(sys.argv[1]).stem
print("\n\nRunning [%s] with [%s]\n\n" % (sys.argv[1],name))
if name == "supercombo":
if len(gpus) > 0:
print("\n\nRunning [%s] with path [%s]\n\n" % (name,sys.argv[1]),file=sys.stderr)
if len(gpus) > 0:
if name == "supercombo":
tf.config.experimental.set_virtual_device_configuration(gpus[0], [tf.config.experimental.VirtualDeviceConfiguration(memory_limit=2048)])
else:
if len(gpus) > 0:
tf.config.experimental.set_virtual_device_configuration(gpus[0], [tf.config.experimental.VirtualDeviceConfiguration(memory_limit=1524)])
with open(f"{model_path / name}.model.keras", "r") as json_file:
m = model_from_json(json_file.read())
m.load_weights(f"{model_path / name}.weights.keras")
else:
tf.config.experimental.set_virtual_device_configuration(gpus[0], [tf.config.experimental.VirtualDeviceConfiguration(memory_limit=300)])
m = load_model(sys.argv[1])
print(m, file=sys.stderr)
bs = [int(np.product(ii.shape[1:])) for ii in m.inputs]
ri = keras.layers.Input((sum(bs),))

tii = []
acc = 0
for i, ii in enumerate(m.inputs):
print(ii, file=sys.stderr)
ti = keras.layers.Lambda(lambda x: x[:,acc:acc+bs[i]], output_shape=(1, bs[i]))(ri)
acc += bs[i]
tr = keras.layers.Reshape(ii.shape[1:])(ti)
tii.append(tr)
no = keras.layers.Concatenate()(m(tii))
m = Model(inputs=ri, outputs=[no])
run_loop(m,name)

79 changes: 79 additions & 0 deletions selfdrive/modeld/runners/keras_runner_split.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/usr/bin/env python3
# TODO: why are the keras models saved with python 2?
from __future__ import print_function

import tensorflow as tf
import os
import sys
import tensorflow.keras as keras
import numpy as np
from tensorflow.keras.models import Model
from tensorflow.keras.models import model_from_json
from pathlib import Path

def read(sz):
dd = []
gt = 0
while gt < sz*4:
st = os.read(0, sz*4 - gt)
assert(len(st) > 0)
dd.append(st)
gt += len(st)
return np.fromstring(b''.join(dd), dtype=np.float32)

def write(d):
os.write(1, d.tobytes())

def run_loop(m,name):
isize = m.inputs[0].shape[1]
osize = m.outputs[0].shape[1]
int
print("ready to run keras model %d -> %d" % (isize, osize), file=sys.stderr)
cnt = 0
while 1:
if name == "supercombo":
cnt = (cnt + 1 ) % 100
if (cnt % 20 == 1):
print("Processing frame %d " % cnt, file=sys.stderr)
# check parent process, if ppid is 1, then modeld is no longer running and the runner should exit.
if os.getppid() == 1:
print("exiting due to Parent PID", file=sys.stderr)
#break
idata = read(isize).reshape((1, isize))
ret = m.predict_on_batch(idata)
if (cnt % 20 == 1):
print(ret, file=sys.stderr)
write(ret)

if __name__ == "__main__":
print(tf.__version__, file=sys.stderr)
# limit gram alloc
gpus = tf.config.experimental.list_physical_devices('GPU')
model_path = Path(sys.argv[1]).parents[0]
name = Path(sys.argv[1]).stem
print("\n\nRunning [%s] with path [%s] and name [%s] from [%s]\n\n" % (sys.argv[1],model_path,name,f"{model_path / name}.weights.keras"),file=sys.stderr)
if name == "supercombo":
if len(gpus) > 0:
tf.config.experimental.set_virtual_device_configuration(gpus[0], [tf.config.experimental.VirtualDeviceConfiguration(memory_limit=2548)])
else:
if len(gpus) > 0:
tf.config.experimental.set_virtual_device_configuration(gpus[0], [tf.config.experimental.VirtualDeviceConfiguration(memory_limit=256)])
with open(f"{model_path / name}.model.keras", "r") as json_file:
m = model_from_json(json_file.read())
m.load_weights(f"{model_path / name}.weights.keras")
print(m, file=sys.stderr)
bs = [int(np.product(ii.shape[1:])) for ii in m.inputs]
ri = keras.layers.Input((sum(bs),))
tii = []
acc = 0
for i, ii in enumerate(m.inputs):
if name == "supercombo":
print("SuperCombo Loading i=%d" % i, file=sys.stderr)
ti = keras.layers.Lambda(lambda x: x[:,acc:acc+bs[i]], output_shape=(1, bs[i]))(ri)
acc += bs[i]
tr = keras.layers.Reshape(ii.shape[1:])(ti)
tii.append(tr)
no = keras.layers.Concatenate()(m(tii))
m = Model(inputs=ri, outputs=[no])
run_loop(m,name)

2 changes: 1 addition & 1 deletion tools/keras/split_keras.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python3
#!/usr/bin/env python3

import tensorflow as tf
import os
Expand Down

0 comments on commit 40ec817

Please sign in to comment.