What's the difference between `tf.train.batch()` and `tf.data.Datasets.from_tensor_slices.batch()`?












0















Recently, I have tried to use ENAS code to automatically design a network on my own datasets.



The code first load data as numpy in main.py, then assign data to model.py for example



# main.py
images, labels = read_data(path)


Then in the model.py it inits the self.x_train and self.y_train as follows:



# model.py
class Model(object):
...
with tf.device("/cpu:0"):
# training data
self.num_train_examples = np.shape(images["train"])[0]
self.num_train_batches = (
self.num_train_examples + self.batch_size - 1) // self.batch_size

x_train, y_train = tf.train.shuffle_batch(
[images["train"], labels["train"]], # images['train'] and labels['train'] are both numpy。array
batch_size=self.batch_size,
capacity=50000,
enqueue_many=True,
num_threads=16,
allow_smaller_final_batch=True,
)


Then in the main.py, the part of running graph is as follows:



# main.py
with tf.train.SingularMonitoredSession(
config=config, hooks=hooks, checkpoint_dir=FLAGS.output_dir) as sess:
start_time = time.time()
while True:
#####################################
###### calculate child ops ########
#####################################

run_ops = [
child_ops["loss"],
child_ops["lr"],
child_ops["grad_norm"],
child_ops["train_acc"],
child_ops["train_op"],
]
loss, lr, gn, tr_acc, _ = sess.run(run_ops)
global_step = sess.run(child_ops["global_step"])
print(sess.run(child_ops['y_train']))
if FLAGS.child_sync_replicas:
actual_step = global_step * FLAGS.num_aggregate
else:
actual_step = global_step
epoch = actual_step // ops["num_train_batches"] # ops["num_train_batches"]
print('Epoch:{}, step:{}'.format(epoch, actual_step))
curr_time = time.time()


What confused me is that the code doesn't define operations, such as self.x_train_next=self.x_train.get_next() or tf.train.Coordinator() to load the next iter data in any .py files.



So the follows are my question:



1.Does tf.train.shuffle_batch automatically load the next batch?



2.What's the difference between tf.train.batch() and tf.data.Datasets.from_tensor_slices.batch()?



3.The original code uses CIFAR10, when I try to use my own dataset, the image size can only set less than 160*160, otherwise it will raise ValueError: GraphDef cannot be larger than 2GB. I had tried to use placeholder or TFRecord to load data, but I don't know when the next batch data is loaded, I have no idea how to change the code. So is there any suggestion to load data?



Many thanks!










share|improve this question



























    0















    Recently, I have tried to use ENAS code to automatically design a network on my own datasets.



    The code first load data as numpy in main.py, then assign data to model.py for example



    # main.py
    images, labels = read_data(path)


    Then in the model.py it inits the self.x_train and self.y_train as follows:



    # model.py
    class Model(object):
    ...
    with tf.device("/cpu:0"):
    # training data
    self.num_train_examples = np.shape(images["train"])[0]
    self.num_train_batches = (
    self.num_train_examples + self.batch_size - 1) // self.batch_size

    x_train, y_train = tf.train.shuffle_batch(
    [images["train"], labels["train"]], # images['train'] and labels['train'] are both numpy。array
    batch_size=self.batch_size,
    capacity=50000,
    enqueue_many=True,
    num_threads=16,
    allow_smaller_final_batch=True,
    )


    Then in the main.py, the part of running graph is as follows:



    # main.py
    with tf.train.SingularMonitoredSession(
    config=config, hooks=hooks, checkpoint_dir=FLAGS.output_dir) as sess:
    start_time = time.time()
    while True:
    #####################################
    ###### calculate child ops ########
    #####################################

    run_ops = [
    child_ops["loss"],
    child_ops["lr"],
    child_ops["grad_norm"],
    child_ops["train_acc"],
    child_ops["train_op"],
    ]
    loss, lr, gn, tr_acc, _ = sess.run(run_ops)
    global_step = sess.run(child_ops["global_step"])
    print(sess.run(child_ops['y_train']))
    if FLAGS.child_sync_replicas:
    actual_step = global_step * FLAGS.num_aggregate
    else:
    actual_step = global_step
    epoch = actual_step // ops["num_train_batches"] # ops["num_train_batches"]
    print('Epoch:{}, step:{}'.format(epoch, actual_step))
    curr_time = time.time()


    What confused me is that the code doesn't define operations, such as self.x_train_next=self.x_train.get_next() or tf.train.Coordinator() to load the next iter data in any .py files.



    So the follows are my question:



    1.Does tf.train.shuffle_batch automatically load the next batch?



    2.What's the difference between tf.train.batch() and tf.data.Datasets.from_tensor_slices.batch()?



    3.The original code uses CIFAR10, when I try to use my own dataset, the image size can only set less than 160*160, otherwise it will raise ValueError: GraphDef cannot be larger than 2GB. I had tried to use placeholder or TFRecord to load data, but I don't know when the next batch data is loaded, I have no idea how to change the code. So is there any suggestion to load data?



    Many thanks!










    share|improve this question

























      0












      0








      0








      Recently, I have tried to use ENAS code to automatically design a network on my own datasets.



      The code first load data as numpy in main.py, then assign data to model.py for example



      # main.py
      images, labels = read_data(path)


      Then in the model.py it inits the self.x_train and self.y_train as follows:



      # model.py
      class Model(object):
      ...
      with tf.device("/cpu:0"):
      # training data
      self.num_train_examples = np.shape(images["train"])[0]
      self.num_train_batches = (
      self.num_train_examples + self.batch_size - 1) // self.batch_size

      x_train, y_train = tf.train.shuffle_batch(
      [images["train"], labels["train"]], # images['train'] and labels['train'] are both numpy。array
      batch_size=self.batch_size,
      capacity=50000,
      enqueue_many=True,
      num_threads=16,
      allow_smaller_final_batch=True,
      )


      Then in the main.py, the part of running graph is as follows:



      # main.py
      with tf.train.SingularMonitoredSession(
      config=config, hooks=hooks, checkpoint_dir=FLAGS.output_dir) as sess:
      start_time = time.time()
      while True:
      #####################################
      ###### calculate child ops ########
      #####################################

      run_ops = [
      child_ops["loss"],
      child_ops["lr"],
      child_ops["grad_norm"],
      child_ops["train_acc"],
      child_ops["train_op"],
      ]
      loss, lr, gn, tr_acc, _ = sess.run(run_ops)
      global_step = sess.run(child_ops["global_step"])
      print(sess.run(child_ops['y_train']))
      if FLAGS.child_sync_replicas:
      actual_step = global_step * FLAGS.num_aggregate
      else:
      actual_step = global_step
      epoch = actual_step // ops["num_train_batches"] # ops["num_train_batches"]
      print('Epoch:{}, step:{}'.format(epoch, actual_step))
      curr_time = time.time()


      What confused me is that the code doesn't define operations, such as self.x_train_next=self.x_train.get_next() or tf.train.Coordinator() to load the next iter data in any .py files.



      So the follows are my question:



      1.Does tf.train.shuffle_batch automatically load the next batch?



      2.What's the difference between tf.train.batch() and tf.data.Datasets.from_tensor_slices.batch()?



      3.The original code uses CIFAR10, when I try to use my own dataset, the image size can only set less than 160*160, otherwise it will raise ValueError: GraphDef cannot be larger than 2GB. I had tried to use placeholder or TFRecord to load data, but I don't know when the next batch data is loaded, I have no idea how to change the code. So is there any suggestion to load data?



      Many thanks!










      share|improve this question














      Recently, I have tried to use ENAS code to automatically design a network on my own datasets.



      The code first load data as numpy in main.py, then assign data to model.py for example



      # main.py
      images, labels = read_data(path)


      Then in the model.py it inits the self.x_train and self.y_train as follows:



      # model.py
      class Model(object):
      ...
      with tf.device("/cpu:0"):
      # training data
      self.num_train_examples = np.shape(images["train"])[0]
      self.num_train_batches = (
      self.num_train_examples + self.batch_size - 1) // self.batch_size

      x_train, y_train = tf.train.shuffle_batch(
      [images["train"], labels["train"]], # images['train'] and labels['train'] are both numpy。array
      batch_size=self.batch_size,
      capacity=50000,
      enqueue_many=True,
      num_threads=16,
      allow_smaller_final_batch=True,
      )


      Then in the main.py, the part of running graph is as follows:



      # main.py
      with tf.train.SingularMonitoredSession(
      config=config, hooks=hooks, checkpoint_dir=FLAGS.output_dir) as sess:
      start_time = time.time()
      while True:
      #####################################
      ###### calculate child ops ########
      #####################################

      run_ops = [
      child_ops["loss"],
      child_ops["lr"],
      child_ops["grad_norm"],
      child_ops["train_acc"],
      child_ops["train_op"],
      ]
      loss, lr, gn, tr_acc, _ = sess.run(run_ops)
      global_step = sess.run(child_ops["global_step"])
      print(sess.run(child_ops['y_train']))
      if FLAGS.child_sync_replicas:
      actual_step = global_step * FLAGS.num_aggregate
      else:
      actual_step = global_step
      epoch = actual_step // ops["num_train_batches"] # ops["num_train_batches"]
      print('Epoch:{}, step:{}'.format(epoch, actual_step))
      curr_time = time.time()


      What confused me is that the code doesn't define operations, such as self.x_train_next=self.x_train.get_next() or tf.train.Coordinator() to load the next iter data in any .py files.



      So the follows are my question:



      1.Does tf.train.shuffle_batch automatically load the next batch?



      2.What's the difference between tf.train.batch() and tf.data.Datasets.from_tensor_slices.batch()?



      3.The original code uses CIFAR10, when I try to use my own dataset, the image size can only set less than 160*160, otherwise it will raise ValueError: GraphDef cannot be larger than 2GB. I had tried to use placeholder or TFRecord to load data, but I don't know when the next batch data is loaded, I have no idea how to change the code. So is there any suggestion to load data?



      Many thanks!







      python tensorflow






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 24 '18 at 2:06









      marsggbomarsggbo

      12




      12
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53454603%2fwhats-the-difference-between-tf-train-batch-and-tf-data-datasets-from-tens%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53454603%2fwhats-the-difference-between-tf-train-batch-and-tf-data-datasets-from-tens%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Costa Masnaga

          Fotorealismo

          Sidney Franklin