Created
July 3, 2019 22:17
-
-
Save fumiakiy/a86a834352c1c2c5a8305e46b3a5e751 to your computer and use it in GitHub Desktop.
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
import re | |
import numpy as np | |
import tensorflow as tf | |
e = [ | |
3080192, | |
3801088, | |
3702784, | |
4325376, | |
4587520, | |
4784128, | |
4620288, | |
4653056, | |
4390912, | |
4096000, | |
3932160, | |
3899392, | |
4390912, | |
4423680, | |
4259840, | |
5308416, | |
5275648, | |
5079040, | |
5013504, | |
4259840, | |
4554752, | |
5472256, | |
6946816, | |
7274496, | |
6717440, | |
6881280, | |
5308416, | |
4751360, | |
5111808, | |
5013504, | |
5832704, | |
5996544, | |
7077888, | |
6356992, | |
5931008, | |
5341184, | |
4390912, | |
2654208, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0 | |
] | |
y = [ | |
5931008, | |
5308416, | |
5013504, | |
3473408, | |
3637248, | |
3964928, | |
3342336, | |
3178496, | |
3899392, | |
4194304, | |
4096000, | |
3604480, | |
3768320, | |
4128768, | |
4259840, | |
3735552, | |
3276800, | |
4554752, | |
4390912, | |
4194304, | |
3932160, | |
4227072, | |
4325376, | |
3997696, | |
3506176, | |
3014656, | |
2752512, | |
655360, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0, | |
0 | |
] | |
# Load TFLite model and allocate tensors. | |
interpreter = tf.contrib.lite.Interpreter(model_path="model1.tflite") | |
interpreter.allocate_tensors() | |
# Get input and output tensors. | |
input_details = interpreter.get_input_details() | |
output_details = interpreter.get_output_details() | |
print(input_details) | |
# Test model on random input data. | |
input_shape = input_details[0]['shape'] | |
# input_data = np.array(np.random.random_sample(input_shape), dtype=np.float32) | |
# input_data = e | |
# input_data = [e] | |
# input_data = [e[0]] | |
# for i in (range(len(y) - 1)): | |
# interpreter.set_tensor(input_details[i]['index'], [y[i]]) | |
indices = [0] * 51 | |
for detail in input_details: | |
vindex = 0 | |
m = re.match(r'Const_(\d+)', detail['name']) | |
if (m is None): | |
vindex = 0 | |
else: | |
vindex = int(m.group(1)) | |
indices[vindex] = detail['index'] | |
for i in range(len(e)-1): | |
interpreter.set_tensor(indices[i], [e[i]]) | |
interpreter.invoke() | |
output_data = interpreter.get_tensor(output_details[0]['index']) | |
print(output_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment