2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

AnimeGANv2をCore MLに変換してiOSでつかう【変換済みモデルあり】

Last updated at Posted at 2020-08-10

変換済みモデル(Hayao,Paprika)GitHubリンクanime.gif

8.6MBの軽量モデル。

グラフをpbtxt形式で保存します。

test.py
tf.train.write_graph(sess.graph_def, './', 'animegan.pbtxt') 

アウトプットノードの名前を調べます。

test.py
graph = sess.graph
print([node.name for node in graph.as_graph_def().node])

凍結グラフを作ります。

from tensorflow.python.tools.freeze_graph import freeze_graph
import tfcoreml

graph_def_file = 'animegan.pbtxt'
checkpoint_file = 'checkpoint/generator_Hayao_weight/Hayao-64.ckpt'
frozen_model_file = './frozen_model.pb'
output_node_names = 'generator/G_MODEL/out_layer/Tanh'

freeze_graph(input_graph=graph_def_file,
             input_saver="",
             input_binary=False,
             input_checkpoint=checkpoint_file,
             output_node_names=output_node_names,
             restore_op_name="save/restore_all",
             filename_tensor_name="save/Const:0",
             output_graph=frozen_model_file,
             clear_devices=True,
             initializer_nodes="")

変換します。

input_tensor_shapes = {'test:0':[1, 256, 256, 3]} # batch size is 1
# Output CoreML model path
coreml_model_file = './animegan.mlmodel'
output_tensor_names = ['generator/G_MODEL/out_layer/Tanh:0']
# Call the converter
coreml_model = tfcoreml.convert(
        tf_model_path='frozen_model.pb',
        mlmodel_path=coreml_model_file,
        input_name_shape_dict=input_tensor_shapes,
        output_feature_names=output_tensor_names,
        image_input_names='test:0',
        red_bias=-1,
        green_bias=-1,
        blue_bias=-1,
        image_scale=2/255,
        minimum_ios_deployment_target='12'
        )

CoreGANContainerを使うと、モデルをプロジェクトにドロップするだけで使えます。

Core MLを使ったアプリを作っています。
機械学習関連の情報を発信しています。

Twitter
[MLBoysチャンネル]
(https://www.youtube.com/channel/UCbHff-wfjTnB3rtXIP6y0xg)
Medium

相棒
note

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?