训练后尝试保存张量流模型时,代码会静默退出

时间:2020-04-06 20:20:28

标签: python tensorflow neural-network

我是tensorflow的新手,无法弄清楚是否正确保存了模型。 我的火车功能看起来像这样:

Stack(
  overflow: Overflow.visible,
  children: <Widget>[
    Container(
      decoration: ...,
      child: ...,
    ),
    Positioned(
      right: -4,
      bottom: -4,
      child: Container(
        width: 9,
        height: 9,
        decoration: new BoxDecoration(
          color: Colors.white,
          shape: BoxShape.circle,
        ),
      ),
    )
  ],
)

在输出中,我得到以下信息:

def train_nn(self, sess, epochs, batch_size, get_batches_fn, train_op, cross_entropy_loss, input_image, label, keep_prob, learning_rate):
        self.keep_prob_value = .5
        self.learning_rate_value = 0.001

        for epoch in range(epochs):
            self.total_loss = 0.0
            print("Epoch %d out of %d."%(epoch+1, epochs))

            for X_batch, gt_batch in get_batches_fn(batch_size):    
                print("Importing a new batch for training.")
                self.loss, _ = sess.run([cross_entropy_loss, train_op], feed_dict={input_image:X_batch, label:gt_batch, keep_prob:self.keep_prob_value, learning_rate:self.learning_rate_value})
                self.total_loss += self.loss

            print("Loss = %s"%self.total_loss)

        print("Trying to save the graph.")
        g = sess.graph
        print("defined graph g")
        gdef = g.as_graph_def()
        print("graph set as default")
        tf.io.train.write_graph(gdef, self.model_directory, os.path.join(self.model_directory, self.model_filename)+".pb", True)
        print("Graph saved successfully.")
        print("Initializing train saver.")
        self.saver = tf.train.Saver()
        print("saving weights")
        self.saver.save(sess, os.path.join(self.model_directory, "weights"))
        print("weights saved")

然后经过一段时间的运行,我的代码停止执行,没有任何其他输出。

0 个答案:

没有答案
相关问题