Skip to content

Commit 8c6a0fa

Browse files
committed
Merge branch 4.x
2 parents 2976f0e + 7c077a7 commit 8c6a0fa

File tree

8 files changed

+32
-2
lines changed

8 files changed

+32
-2
lines changed

testdata/dnn/tensorflow/generate_tf2_models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ def saveBroken(graph, name):
7676
save(model, 'tf2_dense', flatten_input=tf.TensorSpec(shape=[None, 1, 2, 3], dtype=tf.float32))
7777
################################################################################
7878
model = tf.keras.models.Sequential([
79-
tf.keras.layers.PReLU(input_shape=(1, 2, 3)),
79+
tf.keras.layers.PReLU(input_shape=(1, 4, 6), alpha_initializer='random_normal'),
8080
])
81-
save(model, 'tf2_prelu', p_re_lu_input=tf.TensorSpec(shape=[None, 1, 2, 3], dtype=tf.float32))
81+
save(model, 'tf2_prelu', p_re_lu_input=tf.TensorSpec(shape=[None, 1, 4, 6], dtype=tf.float32))
8282
################################################################################
8383
model = tf.keras.models.Sequential([
8484
tf.keras.layers.AveragePooling2D(input_shape=(4, 6, 3), pool_size=(2, 2)),
72 Bytes
Binary file not shown.
-231 Bytes
Binary file not shown.
72 Bytes
Binary file not shown.

testdata/dnn/tflite/generate.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,33 @@ def run_mediapipe_solution(solution, inp_size):
4545
run_tflite_model("face_detection_short_range", (128, 128))
4646

4747
run_mediapipe_solution(mp.solutions.selfie_segmentation.SelfieSegmentation(model_selection=0), (256, 256))
48+
49+
# Save TensorFlow model as TFLite
50+
def save_tflite_model(model, inp, name):
51+
func = model.get_concrete_function()
52+
converter = tf.lite.TFLiteConverter.from_concrete_functions([func])
53+
tflite_model = converter.convert()
54+
55+
interpreter = tf.lite.Interpreter(model_content=tflite_model)
56+
57+
with open(f'{name}.tflite', 'wb') as f:
58+
f.write(tflite_model)
59+
60+
out = model(inp)
61+
62+
np.save(f'{name}_inp.npy', inp.transpose(0, 3, 1, 2))
63+
np.save(f'{name}_out_Identity.npy', np.array(out).transpose(0, 3, 1, 2))
64+
65+
66+
@tf.function(input_signature=[tf.TensorSpec(shape=[1, 3, 3, 1], dtype=tf.float32)])
67+
def replicate_by_pack(x):
68+
pack_1 = tf.stack([x, x], axis=3)
69+
reshape_1 = tf.reshape(pack_1, [1, 3, 6, 1])
70+
pack_2 = tf.stack([reshape_1, reshape_1], axis=2)
71+
reshape_2 = tf.reshape(pack_2, [1, 6, 6, 1])
72+
scaled = tf.image.resize(reshape_2, size=(3, 3), method=tf.image.ResizeMethod.NEAREST_NEIGHBOR)
73+
return scaled + x
74+
75+
inp = np.random.standard_normal((1, 3, 3, 1)).astype(np.float32)
76+
save_tflite_model(replicate_by_pack, inp, 'replicate_by_pack')
77+
1.63 KB
Binary file not shown.
164 Bytes
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)