我想在磁盘文件中保存一个Btree(不确定二进制文件).然后将其读入内存.某些Level-order遍历可能是二进制Btree的好方法.但如果它不是二元的那个.我将叶子节点中的Btree构建到内存中的rootnode.我相信我必须在磁盘文件中定义一些结构并输出树节点.使用一些额外的标签来识别文件中的节点?如何遍历可能是这里的关键问题.我不知道保存节点和指针的好方法.然后阅读它.在记忆中构建树.有什么好主意吗?非常感谢.
操作系统平台和发行版:Linux Ubuntu 14.04
TensorFlow版本:来自二进制的Tensorflow(1.4.0)
CUDA / cuDNN版本:CUDA 8.0
我已经使用tensorflow训练了一些自定义模型,并试图使其成为移动应用程序的tensorflow lite模型。
我的模型定义如下:
def P_Net(inputs,label=None,bbox_target=None,landmark_target=None,training=True):
#define common param
with slim.arg_scope([slim.conv2d],
activation_fn=prelu,
weights_initializer=slim.xavier_initializer(),
biases_initializer=tf.zeros_initializer(),
weights_regularizer=slim.l2_regularizer(0.0005),
padding='valid'):
print inputs.get_shape()
net = slim.conv2d(inputs, 28, 3, stride=1,scope='conv1')
......
conv4_1 = slim.conv2d(net,num_outputs=2,kernel_size=[1,1],stride=1,scope='conv4_1',activation_fn=tf.nn.softmax)
#conv4_1 = slim.conv2d(net,num_outputs=1,kernel_size=[1,1],stride=1,scope='conv4_1',activation_fn=tf.nn.sigmoid)
print conv4_1.get_shape()
#batch*H*W*4
bbox_pred = slim.conv2d(net,num_outputs=4,kernel_size=[1,1],stride=1,scope='conv4_2',activation_fn=None)
print bbox_pred.get_shape()
Run Code Online (Sandbox Code Playgroud)
其中conv4_1和conv4_2是输出层。
我冻结模型:
freeze_graph.freeze_graph('out_put_model/model.pb', '', False, model_path, 'Squeeze,Squeeze_1', '', '', 'out_put_model/frozen_model.pb', '', '')
Run Code Online (Sandbox Code Playgroud)
之后,我可以使用张量板查看图形。并将其读回以进行仔细检查,然后从检查点将事物身份输出到模型。
然后我尝试将Frozen_model.pb保存到tensorflow lite模型。找到tensorflow 1.4.0没有tensorflow lite模块,我从github检出tensorflow,然后bazel运行toco像这样:
bazel run --config=opt //tensorflow/contrib/lite/toco:toco -- --input_file='/home/sens/mtcnn_cat/MTCNN-Tensorflow/test/out_put_model/frozen_model.pb' --output_file='/home/sens/mtcnn_cat/MTCNN-Tensorflow/test/out_put_model/pnet.tflite' --inference_type=FLOAT --input_shape=1,128,128,3 --input_array=image_height,image_width,input_image --output_array=Squeeze,Squeeze_1 --input_format=TENSORFLOW_GRAPHDEF --output_format=TFLITE --dump_graphviz=/tmp
Run Code Online (Sandbox Code Playgroud)
但是,输出抱怨找不到输出数组:
INFO: Running …
Run Code Online (Sandbox Code Playgroud) 我试图用java代码在Android设备中编写和读取浮点数组(实际上相当大,640*480).喜欢这个
DataOutputStream out = ...;
for (int i=0; i<floatarray.length; ++i)
out.writeFloat(floatarray[i]);
Run Code Online (Sandbox Code Playgroud)
非常慢,我已经尝试过了.
写:
float[] test=new float[3];
test[0]=1.0f;
test[1]=1.2f;
test[2]=1.5f;
//long timeBeforeWrite = System.nanoTime();
try {
BufferedOutputStream dataOut = new BufferedOutputStream (
new FileOutputStream("/sdcard/DCIM/Camera/Dual/demo.bin"));
byte buf[]=new byte[4*test.length];
long timeBeforeWrite = System.nanoTime();
for (int i=0; i<test.length; ++i)
{
int val = Float.floatToRawIntBits(test[i]);
buf[4 * i] = (byte) (val >> 24);
buf[4 * i + 1] = (byte) (val >> 16) ;
buf[4 * i + 2] = (byte) (val >> 8); …
Run Code Online (Sandbox Code Playgroud)