日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android: 生成安卓可使用的Tflite文件

發布時間:2023/12/31 Android 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android: 生成安卓可使用的Tflite文件 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一:把keras模型轉換為tensorflow模型

???? H5-to-pb文件,H5模型必須同時包含模型結構和結構參數,

??? 參考文章 忘記了

def h5_to_pb(self,h5_model, output_dir, model_name, out_prefix="output_", log_tensorboard=True):""".h5模型文件轉換成pb模型文件Argument:h5_model: str.h5模型文件output_dir: strpb模型文件保存路徑model_name: strpb模型文件名稱out_prefix: str根據訓練,需要修改log_tensorboard: bool是否生成日志文件Return:pb模型文件"""if os.path.exists(output_dir) == False:os.mkdir(output_dir)out_nodes = []for i in range(len(h5_model.outputs)):out_nodes.append(out_prefix + str(i + 1))tf.identity(h5_model.output[i], out_prefix + str(i + 1))sess = backend.get_session()from tensorflow.python.framework import graph_util, graph_io# 寫入pb模型文件init_graph = sess.graph.as_graph_def()main_graph = graph_util.convert_variables_to_constants(sess, init_graph, out_nodes)graph_io.write_graph(main_graph, output_dir, name=model_name, as_text=False)# 輸出日志文件if log_tensorboard:from tensorflow.python.tools import import_pb_to_tensorboardimport_pb_to_tensorboard.import_to_tensorboard(os.path.join(output_dir, model_name), output_dir)

? 結果:生成一個frozen模型

?

二.把pb模型轉化為Tflite模型

文鏈:Google官方文檔;

Multiple output arrays

The flag output_arrays takes in a comma-separated list of output arrays as seen in the example below. This is useful for models or subgraphs with multiple outputs.

curl https://storage.googleapis.com/download.tensorflow.org/models/inception_v1_2016_08_28_frozen.pb.tar.gz \| tar xzv -C /tmp tflite_convert \--graph_def_file=/tmp/inception_v1_2016_08_28_frozen.pb \--output_file=/tmp/foo.tflite \--input_arrays=input \--output_arrays=InceptionV1/InceptionV1/Mixed_3b/Branch_1/Conv2d_0a_1x1/Relu,InceptionV1/InceptionV1/Mixed_3b/Branch_2/Conv2d_0a_1x1/Relu

?

?

?

?

?

總結

以上是生活随笔為你收集整理的Android: 生成安卓可使用的Tflite文件的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。