aboutsummarylogtreecommitdiffstats
path: root/make_c_model.py
blob: 86810746880340747178ec3c04fd84c0a819ee5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# From https://github.com/AmirulOm/tensorflow_capi_sample
#  via https://medium.com/analytics-vidhya/deploying-tensorflow-2-1-as-c-c-executable-1d090845055c

import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '1' # 0 is everything; 1 is warnings and above, I guess

import numpy as np
import tensorflow as tf

class testModel(tf.keras.Model):
  def __init__(self):
    super(testModel, self).__init__()
    self.dense1 = tf.keras.layers.Dense(1, kernel_initializer='Ones', activation=tf.nn.relu)
  def call(self, inputs):
    return self.dense1(inputs)

input_data = np.asarray([[10]])
module = testModel()
# module._set_inputs(input_data) # This step does not change the output.
repr(module(input_data))

module.save('c_model') # save_format='tf' is the default.
import subprocess
subprocess.run(['tar', '-czvf', 'c_model.tar.gz', 'c_model'])