提交 89d03b05 编写于 作者: D Dmitry Kurtaev

Update test data

上级 06b91360
......@@ -48,31 +48,30 @@ run_mediapipe_solution(mp.solutions.selfie_segmentation.SelfieSegmentation(model
# Save TensorFlow model as TFLite
def save_tflite_model(model, inp, name):
func = model.__call__.get_concrete_function()
converter = tf.lite.TFLiteConverter.from_concrete_functions([func], model)
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_PartitionedCall:0.npy', np.array(out).transpose(0, 3, 1, 2))
np.save(f'{name}_out_Identity.npy', np.array(out).transpose(0, 3, 1, 2))
class ReplicateByPack(tf.Module):
@tf.function(input_signature=[tf.TensorSpec(shape=[1, 3, 3, 1], dtype=tf.float32)])
def __call__(self, 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
@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
model = ReplicateByPack()
inp = np.random.standard_normal((1, 3, 3, 1)).astype(np.float32)
save_tflite_model(model, inp, 'replicate_by_pack')
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.
先完成此消息的编辑!
想要评论请 注册