提交 8c6a0fa3 编写于 作者: A Alexander Smorkalov

Merge branch 4.x

......@@ -76,9 +76,9 @@ model = tf.keras.models.Sequential([
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)),
......
......@@ -45,3 +45,33 @@ run_tflite_model("face_landmark", (192, 192))
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')
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册