使用tf.saved_model.builder保存的“.pb”模型只包含图形或图形和权重?

时间:2017-12-15 10:25:12

标签: tensorflow

以下代码包含Tensorflow图和模型:

X =  tf.placeholder(tf.float32, [None,training_set.shape[1]],name = 'X')
Y = tf.placeholder(tf.float32,[None,training_labels.shape[1]], name = 'Y')
print("tensorflow shuffling")

A1 = tf.contrib.layers.fully_connected(X, num_outputs = 50, activation_fn = tf.nn.relu)
A1 = tf.nn.dropout(A1, 0.8)
A2 = tf.contrib.layers.fully_connected(A1, num_outputs = 2, activation_fn = None)
cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(logits = A2, labels = Y))
global_step = tf.Variable(0, trainable=False)
start_learning_rate = 0.001
learning_rate = tf.train.exponential_decay(start_learning_rate, global_step, 200, 0.1, True )
optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate).minimize(cost)

init = tf.global_variables_initializer()

builder = tf.saved_model.builder.SavedModelBuilder('./SavedModel/')

num_epochs = 2000
mini_batches = 100
with tf.Session() as sess:
    sess.run(init)
    for i in range(num_epochs):
        mini_batch_size = int(training_set.shape[0] / mini_batches)
        for j in range(mini_batches):
            _,cost_one=sess.run([optimizer,cost], feed_dict={X: training_set[mini_batch_size * j:mini_batch_size * (j+1),: ], Y: training_labels[mini_batch_size*j:mini_batch_size*(j+1),:]})
        predict_op = tf.argmax(A2, 1)
        correct_prediction = tf.equal(predict_op, tf.argmax(Y, 1))
    builder.add_meta_graph_and_variables(sess,
                                       [tf.saved_model.tag_constants.TRAINING],
                                       signature_def_map=None,
                                       assets_collection=None)
    builder.save() 

这将创建一个“SavedModel”文件夹,其中包含savedmodel.pb和另一个文件夹“variables”,其中包含variables.data-00000-of-00001和variables.index。现在我想了解savedmodel.pb包含什么?它是否仅包含图形或图形以及权重?

0 个答案:

没有答案