質問編集履歴
1
fiveHundred さんに指摘していただいたところを修正しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,15 +4,44 @@
|
|
4
4
|
サイトのURL:https://rightcode.co.jp/blog/information-technology/tensorflow-model-file-conversion-important-point
|
5
5
|
### 発生している問題・エラーメッセージ
|
6
6
|
|
7
|
-
|
7
|
+
|
8
8
|
エラーもなく変換できているのですが、変換されたtfliteファイルが1KBとサイズが小さすぎて困ってます
|
9
|
+
###変換をしたコード
|
9
10
|
```
|
11
|
+
#tensorflowをインストールする
|
12
|
+
!pip install tensorflow
|
13
|
+
#tensorflowのバージョンを確かめる
|
14
|
+
try:
|
15
|
+
%tensorflow_version 2.x
|
16
|
+
except Exception:
|
17
|
+
pass
|
10
18
|
|
19
|
+
import tensorflow as tf
|
20
|
+
from tensorflow.keras import layers
|
11
21
|
|
22
|
+
print("TF version:", tf.__version__)
|
23
|
+
#tfliteに変換する
|
24
|
+
# 基本的な関数を構築
|
25
|
+
root = tf.train.Checkpoint()
|
26
|
+
root.v1 = tf.Variable(3.)
|
27
|
+
root.v2 = tf.Variable(2.)
|
28
|
+
root.f = tf.function(lambda x: root.v1 * root.v2 * x)
|
12
29
|
|
30
|
+
# モデルを保存
|
31
|
+
export_dir = "/tmp/test_saved_model"
|
32
|
+
input_data = tf.constant(1., shape=[1, 1])
|
33
|
+
to_save = root.f.get_concrete_function(input_data)
|
34
|
+
tf.saved_model.save(root, export_dir, to_save)
|
35
|
+
|
36
|
+
# モデルを変換
|
37
|
+
converter = tf.lite.TFLiteConverter.from_saved_model(export_dir)
|
38
|
+
tflite_model = converter.convert()
|
39
|
+
!ls /tmp/test_saved_model
|
40
|
+
open('savedmodel-model.tflite', 'wb').write(tflite_model)
|
41
|
+
```
|
13
42
|
### 試したこと
|
14
43
|
学習済みデータを変えました。
|
15
|
-
|
44
|
+
pbファイルのほかにpbtxtファイルも付け足してやりました。
|
16
45
|
### 補足情報
|
17
46
|
学習済みデータは、下のURLのサイトを参考にしてやりました。
|
18
47
|
サイトのURL:https://qiita.com/tsota/items/123514cbfd036e6bd808#1-cloud-annotations%E3%81%A7%E3%82%A2%E3%83%8E%E3%83%86%E3%83%BC%E3%82%B7%E3%83%A7%E3%83%B3
|