tf是封装的真好,我是真菜——导入数据
with tf.Session() as sess: # The `Iterator.string_handle()` method returns a tensor that can be evaluated # and used to feed the `handle` placeholder. training_handle = sess.run(training_iterator.string_handle()) validation_handle = sess.run(validation_iterator.string_handle()) # Loop forever, alternating between training and validation. while True: # Run 200 steps using the training dataset. Note that the training dataset is # infinite, and we resume from where we left off in the previous `while` loop # iteration. sess.run(training_iterator.initializer) for _ in range(5): batch_images_tf_value,batch_labels_tf_value,_ = sess.run( iterator.get_next(), feed_dict={handle: training_handle}) print("train:",batch_images_tf_value.shape) # Run one pass over the validation dataset. sess.run(validation_iterator.initializer) for _ in range(5): batch_images_tf_value,batch_labels_tf_value,_ = sess.run(iterator.get_next(), feed_dict={handle: validation_handle}) print("val:",batch_images_tf_value.shape)
ref:https://blog.csdn.net/weixin_39506322/article/details/82455860