Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions testdata/dnn/tensorflow/generate_tf2_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ def saveBroken(graph, name):
save(model, 'tf2_dense', flatten_input=tf.TensorSpec(shape=[None, 1, 2, 3], dtype=tf.float32))
################################################################################
model = tf.keras.models.Sequential([
tf.keras.layers.PReLU(input_shape=(1, 2, 3)),
tf.keras.layers.PReLU(input_shape=(1, 4, 6), alpha_initializer='random_normal'),
])
save(model, 'tf2_prelu', p_re_lu_input=tf.TensorSpec(shape=[None, 1, 2, 3], dtype=tf.float32))
save(model, 'tf2_prelu', p_re_lu_input=tf.TensorSpec(shape=[None, 1, 4, 6], dtype=tf.float32))
################################################################################
model = tf.keras.models.Sequential([
tf.keras.layers.AveragePooling2D(input_shape=(4, 6, 3), pool_size=(2, 2)),
Expand Down
Binary file modified testdata/dnn/tensorflow/tf2_prelu_in.npy
Binary file not shown.
Binary file modified testdata/dnn/tensorflow/tf2_prelu_net.pb
Binary file not shown.
Binary file modified testdata/dnn/tensorflow/tf2_prelu_out.npy
Binary file not shown.
30 changes: 30 additions & 0 deletions testdata/dnn/tflite/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,33 @@ def run_mediapipe_solution(solution, inp_size):
run_tflite_model("face_detection_short_range", (128, 128))

run_mediapipe_solution(mp.solutions.selfie_segmentation.SelfieSegmentation(model_selection=0), (256, 256))

# Save TensorFlow model as TFLite
def save_tflite_model(model, inp, name):
func = model.get_concrete_function()
converter = tf.lite.TFLiteConverter.from_concrete_functions([func])
tflite_model = converter.convert()

interpreter = tf.lite.Interpreter(model_content=tflite_model)

with open(f'{name}.tflite', 'wb') as f:
f.write(tflite_model)

out = model(inp)

np.save(f'{name}_inp.npy', inp.transpose(0, 3, 1, 2))
np.save(f'{name}_out_Identity.npy', np.array(out).transpose(0, 3, 1, 2))


@tf.function(input_signature=[tf.TensorSpec(shape=[1, 3, 3, 1], dtype=tf.float32)])
def replicate_by_pack(x):
pack_1 = tf.stack([x, x], axis=3)
reshape_1 = tf.reshape(pack_1, [1, 3, 6, 1])
pack_2 = tf.stack([reshape_1, reshape_1], axis=2)
reshape_2 = tf.reshape(pack_2, [1, 6, 6, 1])
scaled = tf.image.resize(reshape_2, size=(3, 3), method=tf.image.ResizeMethod.NEAREST_NEIGHBOR)
return scaled + x

inp = np.random.standard_normal((1, 3, 3, 1)).astype(np.float32)
save_tflite_model(replicate_by_pack, inp, 'replicate_by_pack')

Binary file added testdata/dnn/tflite/replicate_by_pack.tflite
Binary file not shown.
Binary file added testdata/dnn/tflite/replicate_by_pack_inp.npy
Binary file not shown.
Binary file not shown.