import tensorflow as tf
import numpy as np
import itertools as it
import importlib

from flowfairy.conf import settings
from flowfairy.utils import take
from flowfairy import data
from flowfairy.feature import FeatureManager
from flowfairy.core.queue import FlowQueue
from flowfairy.core.stage import stage


def load_net():
    net = importlib.import_module(settings.NET).Net()
    return net

def run(*args, **options):

    coord = tf.train.Coordinator()
    net = load_net()

    queues = []
    with tf.variable_scope('network') as scope:
        for data_loader in data.provider:
            fts = FeatureManager(data_loader)
            queue = FlowQueue(fts, coord)
            queues.append(queue)

            X = queue.dequeue()

            func = getattr(net, data_loader.name)
            func(**dict(zip(fts.fields, X)))
            scope.reuse_variables()

    with tf.Session() as sess:

        stage.before(sess, net)
        for queue in queues: queue.start(sess)

        sess.run(tf.global_variables_initializer())

        try:
            step = 1
            while not coord.should_stop() and not net.should_stop():

                stage.run(sess, step)

                step += 1
        except KeyboardInterrupt:
            pass

        coord.request_stop()
        queue.stop()
        coord.join(stop_grace_period_secs=5)

import tensorflow as tf
import numpy as np
import itertools as it
import importlib

from flowfairy.conf import settings
from flowfairy.utils import take
from flowfairy import data
from flowfairy.feature import FeatureManager
from flowfairy.core.queue import FlowQueue
from flowfairy.core.stage import stage


def load_net():
    net = importlib.import_module(settings.NET).Net()
    return net

def run(*args, **options):

    coord = tf.train.Coordinator()
    net = load_net()

    queues = []
    for data_loader in data.provider:
        with tf.variable_scope(data_loader.name) as scope:
            fts = FeatureManager(data_loader)
            queue = FlowQueue(fts, coord)
            queues.append(queue)

            X = queue.dequeue()

            func = getattr(net, data_loader.name)
            func(**dict(zip(fts.fields, X)))
            scope.reuse_variables()

    with tf.Session() as sess:

        stage.before(sess, net)
        for queue in queues: queue.start(sess)

        sess.run(tf.global_variables_initializer())

        try:
            step = 1
            while not coord.should_stop() and not net.should_stop():

                stage.run(sess, step)

                step += 1
        except KeyboardInterrupt:
            pass

        coord.request_stop()
        queue.stop()
        coord.join(stop_grace_period_secs=5)

Set name_scope of entire network to the dataset it handles
Set name_scope of entire network to the dataset it handles

  import tensorflow as tf
  import numpy as np
  import itertools as it
  import importlib
  
  from flowfairy.conf import settings
  from flowfairy.utils import take
  from flowfairy import data
  from flowfairy.feature import FeatureManager
  from flowfairy.core.queue import FlowQueue
  from flowfairy.core.stage import stage
  
  
  def load_net():
      net = importlib.import_module(settings.NET).Net()
      return net
  
  def run(*args, **options):
  
      coord = tf.train.Coordinator()
      net = load_net()
  
      queues = []
-     with tf.variable_scope('network') as scope:
-         for data_loader in data.provider:
+     for data_loader in data.provider:
+         with tf.variable_scope(data_loader.name) as scope:
              fts = FeatureManager(data_loader)
              queue = FlowQueue(fts, coord)
              queues.append(queue)
  
              X = queue.dequeue()
  
              func = getattr(net, data_loader.name)
              func(**dict(zip(fts.fields, X)))
              scope.reuse_variables()
  
      with tf.Session() as sess:
  
          stage.before(sess, net)
          for queue in queues: queue.start(sess)
  
          sess.run(tf.global_variables_initializer())
  
          try:
              step = 1
              while not coord.should_stop() and not net.should_stop():
  
                  stage.run(sess, step)
  
                  step += 1
          except KeyboardInterrupt:
              pass
  
          coord.request_stop()
          queue.stop()
          coord.join(stop_grace_period_secs=5)
  
Set name_scope of entire network to the dataset it handles
## Code Before:
import tensorflow as tf
import numpy as np
import itertools as it
import importlib

from flowfairy.conf import settings
from flowfairy.utils import take
from flowfairy import data
from flowfairy.feature import FeatureManager
from flowfairy.core.queue import FlowQueue
from flowfairy.core.stage import stage


def load_net():
    net = importlib.import_module(settings.NET).Net()
    return net

def run(*args, **options):

    coord = tf.train.Coordinator()
    net = load_net()

    queues = []
    with tf.variable_scope('network') as scope:
        for data_loader in data.provider:
            fts = FeatureManager(data_loader)
            queue = FlowQueue(fts, coord)
            queues.append(queue)

            X = queue.dequeue()

            func = getattr(net, data_loader.name)
            func(**dict(zip(fts.fields, X)))
            scope.reuse_variables()

    with tf.Session() as sess:

        stage.before(sess, net)
        for queue in queues: queue.start(sess)

        sess.run(tf.global_variables_initializer())

        try:
            step = 1
            while not coord.should_stop() and not net.should_stop():

                stage.run(sess, step)

                step += 1
        except KeyboardInterrupt:
            pass

        coord.request_stop()
        queue.stop()
        coord.join(stop_grace_period_secs=5)

## Instruction:
Set name_scope of entire network to the dataset it handles
## Code After:
import tensorflow as tf
import numpy as np
import itertools as it
import importlib

from flowfairy.conf import settings
from flowfairy.utils import take
from flowfairy import data
from flowfairy.feature import FeatureManager
from flowfairy.core.queue import FlowQueue
from flowfairy.core.stage import stage


def load_net():
    net = importlib.import_module(settings.NET).Net()
    return net

def run(*args, **options):

    coord = tf.train.Coordinator()
    net = load_net()

    queues = []
    for data_loader in data.provider:
        with tf.variable_scope(data_loader.name) as scope:
            fts = FeatureManager(data_loader)
            queue = FlowQueue(fts, coord)
            queues.append(queue)

            X = queue.dequeue()

            func = getattr(net, data_loader.name)
            func(**dict(zip(fts.fields, X)))
            scope.reuse_variables()

    with tf.Session() as sess:

        stage.before(sess, net)
        for queue in queues: queue.start(sess)

        sess.run(tf.global_variables_initializer())

        try:
            step = 1
            while not coord.should_stop() and not net.should_stop():

                stage.run(sess, step)

                step += 1
        except KeyboardInterrupt:
            pass

        coord.request_stop()
        queue.stop()
        coord.join(stop_grace_period_secs=5)
