Saya mencoba menyimpan model tensorflow saya dari google colab tetapi itu memberi saya kesalahan. Saya tidak tahu mengapa itu memberikan kesalahan terkait dengan sesuatu yang terjadi dengan 'Tidak dapat membuat serial buffer protokol tipe tensorflow.GraphDef sebagai ukuran serial (2897149641bytes) akan lebih besar dari batas (2147483647 byte)' saya melampirkan kode yang saya gunakan juga, di bawah ini saya telah melampirkan kesalahan yang muncul

x = tf.placeholder(tf.float32, shape = [None, 4])
y_true = tf.placeholder(tf.float32, shape = [None, 4])

hidden_layer_1 = tf.layers.dense(x, 100, activation = tf.nn.relu)
hidden_layer_2 = tf.layers.dense(hidden_layer_1, 100, activation = tf.nn.relu)
output = tf.layers.dense(hidden_layer_2, 4, activation = tf.nn.sigmoid)

cost_func = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(labels=y_true,logits=output))
optimizer = tf.train.AdamOptimizer(learning_rate=0.001)
train = optimizer.minimize(cost_func)

init = tf.global_variables_initializer()
saver = tf.train.Saver()

steps = 100
cost_train = []
cost_test = []
accu_train = []
accu_test = []
with tf.Session() as sess:

    sess.run(init)

    for i in range(steps):


        _, c_train, pred_train = sess.run([train, cost_func, output],feed_dict={x:X_train,y_true:y_train})
        _, c_test, pred_test = sess.run([train, cost_func, output],feed_dict={x:X_test,y_true:y_test})

        matches_train = tf.equal(tf.argmax(pred_train,1),tf.argmax(y_train,1))
        matches_test = tf.equal(tf.argmax(pred_test,1),tf.argmax(y_test,1))

        acc_train = tf.reduce_mean(tf.cast(matches_train,tf.float32))
        acc_test = tf.reduce_mean(tf.cast(matches_test,tf.float32))

        a_train = sess.run(acc_train,feed_dict={x:X_train,y_true:y_train,})
        a_test = sess.run(acc_test,feed_dict={x:X_test,y_true:y_test,})

        cost_train.append(c_train)
        cost_test.append(c_test)

        accu_train.append(a_train)
        accu_test.append(a_test)

        print('Currently on step {}'.format(i))
        print('TRAIN ERROR =', c_train,  '\t', 'TEST ERROR =', c_test)
        print('TRAIN ACCURACY =', a_train,  '\t', 'TEST ACCURACY =', a_test)
        print('---------------------------------------------------------------------------------------------------------------------------------------------------------')
    save_path = saver.save(sess, "/content/drive/My Drive/data/model/model.ckpt")
    final_pred = sess.run(output,feed_dict={x:test})
---------------------------------------------------------------------------
InvalidArgumentError                      Traceback (most recent call last)
<ipython-input-56-f10b5e5ffc9f> in <module>()
     29         accu_test.append(a_test)
     30 
---> 31         save_path = saver.save(sess, "model.ckpt")
     32 
     33         print('Currently on step {}'.format(i))

3 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/training/saver.py in save(self, sess, save_path, global_step, latest_filename, meta_graph_suffix, write_meta_graph, write_state, strip_default_attrs, save_debug_info)
   1198               meta_graph_filename,
   1199               strip_default_attrs=strip_default_attrs,
-> 1200               save_debug_info=save_debug_info)
   1201 
   1202     if self._is_empty:

/usr/local/lib/python3.6/dist-packages/tensorflow/python/training/saver.py in export_meta_graph(self, filename, collection_list, as_text, export_scope, clear_devices, clear_extraneous_savers, strip_default_attrs, save_debug_info)
   1241     return export_meta_graph(
   1242         filename=filename,
-> 1243         graph_def=ops.get_default_graph().as_graph_def(add_shapes=True),
   1244         saver_def=self.saver_def,
   1245         collection_list=collection_list,

/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py in as_graph_def(self, from_version, add_shapes)
   3463     """
   3464     # pylint: enable=line-too-long
-> 3465     result, _ = self._as_graph_def(from_version, add_shapes)
   3466     return result
   3467 

/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/ops.py in _as_graph_def(self, from_version, add_shapes)
   3388     with self._lock:
   3389       with c_api_util.tf_buffer() as buf:
-> 3390         c_api.TF_GraphToGraphDef(self._c_graph, buf)
   3391         data = c_api.TF_GetBuffer(buf)
   3392       graph = graph_pb2.GraphDef()

InvalidArgumentError: Cannot serialize protocol buffer of type tensorflow.GraphDef as the serialized size (2897149641bytes) would be larger than the limit (2147483647 bytes)
0
user10867289 9 Agustus 2019, 20:28

1 menjawab

Jawaban Terbaik

Anda membuat matches_train/test dan acc_train/test sebagai Tensor setiap kali loop berjalan dan mereka ditambahkan ke grafik. Pindahkan mereka di luar loop, atau ganti dengan fungsi numpy.

0
geometrikal 9 Agustus 2019, 22:27