Skip to content

Instantly share code, notes, and snippets.

@margaretmz
margaretmz / selfie2anime-run-benchmark.py
Last active August 15, 2020 15:12
selfie2anime-run-benchmark
adb shell /data/local/tmp/benchmark_model
--graph=/data/local/tmp/selfie2anime.tflite
--num_threads=4
@margaretmz
margaretmz / selfie2anime-adb.py
Last active July 13, 2020 04:35
selfie2anime-adb
adb install -r -d -g bazel-bin/tensorflow/lite/tools/benchmark/android/benchmark_model.apk
adb push selfie2anime.tflite /data/local/tmp
@margaretmz
margaretmz / selfie2animie-build-benchmarking-tool
Created July 13, 2020 01:02
selfie2animie-build-benchmarking-tool
bazel build -c opt \
--config=android_arm64 \
//tensorflow/lite/tools/benchmark:benchmark_model
@margaretmz
margaretmz / selfie2anime-metada-after
Last active July 12, 2020 18:16
selfie2anime_metada_after
metadata_writer_for_selfie2anime.py
|-- model_without_metadata
| |--selfie2anime.tflite
|-- model_with_metadata
| |--selfie2anime.tflite
| |--selfie2anime.json
@margaretmz
margaretmz / selfie2animie-metadata-before
Last active July 12, 2020 18:15
selfie2animie-metadata-before
metadata_writer_for_selfie2anime.py
|-- model_without_metadata
| |--selfie2anime.tflite
|-- model_with_metadata
@margaretmz
margaretmz / selfie2anime-add-metadata
Created July 12, 2020 00:45
selfie2anime-add-metadata
python ./metadata_writer_for_selfie2anime.py \
--model_file=./model_without_metadata/selfie2anime.tflite \
--export_directory=model_with_metadata
@margaretmz
margaretmz / selfie2anime-tflite-conversion.py
Last active July 13, 2020 04:32
selfie2anime-tflite-conversion
converter = tf.lite.TFLiteConverter.from_concrete_functions([concrete_func])
converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_SIZE]
tflite_model = converter.convert()
@margaretmz
margaretmz / selfie2anime-concrete-func.py
Last active July 13, 2020 04:32
selfie2anime-concrete-func
concrete_func.inputs[0].set_shape([1, 256, 256, 3])
concrete_func.outputs[0].set_shape([1, 256, 256, 3])
@margaretmz
margaretmz / selfie2anime-load-savedmodel.py
Last active July 13, 2020 04:32
selfie2anime-load-savedmodel
model = tf.saved_model.load(saved_model_path)
concrete_func = model.signatures[ tf.saved_model.DEFAULT_SERVING_SIGNATURE_DEF_KEY]
@margaretmz
margaretmz / selfie2anime-save-model.py
Last active July 13, 2020 04:31
selfie2anime-save-model
tf.saved_model.simple_save(
sess,
saved_model_dir,
inputs={gan.test_domain_A.name: gan.test_domain_A},
outputs={gan.test_fake_B.name: gan.test_fake_B}
)