Python tensorflow.reset_default_graph() Examples

The following are 30 code examples of tensorflow.reset_default_graph(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module tensorflow , or try the search function .
Example #1
Source File: mnist_tf_keras.py    From deep_architect with MIT License 6 votes vote down vote up
def evaluate(self, inputs, outputs):
        tf.keras.backend.clear_session()
        tf.reset_default_graph()

        (x_train, y_train) = self.train_dataset

        X = tf.keras.layers.Input(x_train[0].shape)
        co.forward({inputs['in']: X})
        logits = outputs['out'].val
        probs = tf.keras.layers.Softmax()(logits)
        model = tf.keras.models.Model(inputs=[inputs['in'].val],
                                      outputs=[probs])
        optimizer = tf.keras.optimizers.Adam(lr=self.learning_rate)
        model.compile(optimizer=optimizer,
                      loss='sparse_categorical_crossentropy',
                      metrics=['accuracy'])
        model.summary()
        history = model.fit(x_train,
                            y_train,
                            batch_size=self.batch_size,
                            epochs=self.max_num_training_epochs,
                            validation_split=self.val_split)

        results = {'val_acc': history.history['val_acc'][-1]}
        return results 
Example #2
Source File: inception_v3_test.py    From DOTA_models with Apache License 2.0 6 votes vote down vote up
def testUnknownImageShape(self):
    tf.reset_default_graph()
    batch_size = 2
    height, width = 299, 299
    num_classes = 1000
    input_np = np.random.uniform(0, 1, (batch_size, height, width, 3))
    with self.test_session() as sess:
      inputs = tf.placeholder(tf.float32, shape=(batch_size, None, None, 3))
      logits, end_points = inception.inception_v3(inputs, num_classes)
      self.assertListEqual(logits.get_shape().as_list(),
                           [batch_size, num_classes])
      pre_pool = end_points['Mixed_7c']
      feed_dict = {inputs: input_np}
      tf.global_variables_initializer().run()
      pre_pool_out = sess.run(pre_pool, feed_dict=feed_dict)
      self.assertListEqual(list(pre_pool_out.shape), [batch_size, 8, 8, 2048]) 
Example #3
Source File: inception_v2_test.py    From DOTA_models with Apache License 2.0 6 votes vote down vote up
def testUnknownImageShape(self):
    tf.reset_default_graph()
    batch_size = 2
    height, width = 224, 224
    num_classes = 1000
    input_np = np.random.uniform(0, 1, (batch_size, height, width, 3))
    with self.test_session() as sess:
      inputs = tf.placeholder(tf.float32, shape=(batch_size, None, None, 3))
      logits, end_points = inception.inception_v2(inputs, num_classes)
      self.assertTrue(logits.op.name.startswith('InceptionV2/Logits'))
      self.assertListEqual(logits.get_shape().as_list(),
                           [batch_size, num_classes])
      pre_pool = end_points['Mixed_5c']
      feed_dict = {inputs: input_np}
      tf.global_variables_initializer().run()
      pre_pool_out = sess.run(pre_pool, feed_dict=feed_dict)
      self.assertListEqual(list(pre_pool_out.shape), [batch_size, 7, 7, 1024]) 
Example #4
Source File: mobilenet_v1_test.py    From DOTA_models with Apache License 2.0 6 votes vote down vote up
def testUnknownImageShape(self):
    tf.reset_default_graph()
    batch_size = 2
    height, width = 224, 224
    num_classes = 1000
    input_np = np.random.uniform(0, 1, (batch_size, height, width, 3))
    with self.test_session() as sess:
      inputs = tf.placeholder(tf.float32, shape=(batch_size, None, None, 3))
      logits, end_points = mobilenet_v1.mobilenet_v1(inputs, num_classes)
      self.assertTrue(logits.op.name.startswith('MobilenetV1/Logits'))
      self.assertListEqual(logits.get_shape().as_list(),
                           [batch_size, num_classes])
      pre_pool = end_points['Conv2d_13_pointwise']
      feed_dict = {inputs: input_np}
      tf.global_variables_initializer().run()
      pre_pool_out = sess.run(pre_pool, feed_dict=feed_dict)
      self.assertListEqual(list(pre_pool_out.shape), [batch_size, 7, 7, 1024]) 
Example #5
Source File: inception_v1_test.py    From DOTA_models with Apache License 2.0 6 votes vote down vote up
def testUnknownImageShape(self):
    tf.reset_default_graph()
    batch_size = 2
    height, width = 224, 224
    num_classes = 1000
    input_np = np.random.uniform(0, 1, (batch_size, height, width, 3))
    with self.test_session() as sess:
      inputs = tf.placeholder(tf.float32, shape=(batch_size, None, None, 3))
      logits, end_points = inception.inception_v1(inputs, num_classes)
      self.assertTrue(logits.op.name.startswith('InceptionV1/Logits'))
      self.assertListEqual(logits.get_shape().as_list(),
                           [batch_size, num_classes])
      pre_pool = end_points['Mixed_5c']
      feed_dict = {inputs: input_np}
      tf.global_variables_initializer().run()
      pre_pool_out = sess.run(pre_pool, feed_dict=feed_dict)
      self.assertListEqual(list(pre_pool_out.shape), [batch_size, 7, 7, 1024]) 
Example #6
Source File: test_model.py    From models with MIT License 6 votes vote down vote up
def network_surgery():
    tf.reset_default_graph()
    inputs = tf.placeholder(tf.float32,
                            shape=(None, 131072, 4),
                            name='inputs')
    targets = tf.placeholder(tf.float32, shape=(None, 1024, 4229),
                             name='targets')
    targets_na = tf.placeholder(tf.bool, shape=(None, 1024), name="targets_na")
    preds_adhoc = tf.placeholder(tf.float32, shape=(None, 960, 4229), name="Placeholder_15")


    saver = tf.train.import_meta_graph("model_files/model.tf.meta",
                                       input_map={'Placeholder_15:0': preds_adhoc,
                                                  'Placeholder:0': targets_na,
                                                  'inputs:0': inputs,
                                                  'targets:0': targets
                                       })

    ops = tf.get_default_graph().get_operations()

    out = tf.train.export_meta_graph(filename='model_files/model.tf-modified.meta', as_text=True)

    ops[:15] 
Example #7
Source File: run_RingNet.py    From RingNet with MIT License 6 votes vote down vote up
def predict_dict(self, images):
        """
        Runs the model with images.
        """
        images_ip = self.graph.get_tensor_by_name(u'input_images_1:0')
        params = self.graph.get_tensor_by_name(u'add_2:0')
        verts = self.graph.get_tensor_by_name(u'Flamenetnormal_2/Add_9:0')
        feed_dict = {
            images_ip: images,
        }
        fetch_dict = {
            'vertices': verts,
            'parameters': params,
        }
        results = self.sess.run(fetch_dict, feed_dict)
        tf.reset_default_graph()
        return results 
Example #8
Source File: dcgan_test.py    From DeepLab_v3 with MIT License 6 votes vote down vote up
def test_generator_graph(self):
    tf.set_random_seed(1234)
    # Check graph construction for a number of image size/depths and batch
    # sizes.
    for i, batch_size in zip(xrange(3, 7), xrange(3, 8)):
      tf.reset_default_graph()
      final_size = 2 ** i
      noise = tf.random_normal([batch_size, 64])
      image, end_points = dcgan.generator(
          noise,
          depth=32,
          final_size=final_size)

      self.assertAllEqual([batch_size, final_size, final_size, 3],
                          image.shape.as_list())

      expected_names = ['deconv%i' % j for j in xrange(1, i)] + ['logits']
      self.assertSetEqual(set(expected_names), set(end_points.keys()))

      # Check layer depths.
      for j in range(1, i):
        layer = end_points['deconv%i' % j]
        self.assertEqual(32 * 2**(i-j-1), layer.get_shape().as_list()[-1]) 
Example #9
Source File: dcgan_test.py    From DeepLab_v3 with MIT License 6 votes vote down vote up
def test_discriminator_graph(self):
    # Check graph construction for a number of image size/depths and batch
    # sizes.
    for i, batch_size in zip(xrange(1, 6), xrange(3, 8)):
      tf.reset_default_graph()
      img_w = 2 ** i
      image = tf.random_uniform([batch_size, img_w, img_w, 3], -1, 1)
      output, end_points = dcgan.discriminator(
          image,
          depth=32)

      self.assertAllEqual([batch_size, 1], output.get_shape().as_list())

      expected_names = ['conv%i' % j for j in xrange(1, i+1)] + ['logits']
      self.assertSetEqual(set(expected_names), set(end_points.keys()))

      # Check layer depths.
      for j in range(1, i+1):
        layer = end_points['conv%i' % j]
        self.assertEqual(32 * 2**(j-1), layer.get_shape().as_list()[-1]) 
Example #10
Source File: mobilenet_v1_test.py    From DeepLab_v3 with MIT License 6 votes vote down vote up
def testUnknownImageShape(self):
    tf.reset_default_graph()
    batch_size = 2
    height, width = 224, 224
    num_classes = 1000
    input_np = np.random.uniform(0, 1, (batch_size, height, width, 3))
    with self.test_session() as sess:
      inputs = tf.placeholder(tf.float32, shape=(batch_size, None, None, 3))
      logits, end_points = mobilenet_v1.mobilenet_v1(inputs, num_classes)
      self.assertTrue(logits.op.name.startswith('MobilenetV1/Logits'))
      self.assertListEqual(logits.get_shape().as_list(),
                           [batch_size, num_classes])
      pre_pool = end_points['Conv2d_13_pointwise']
      feed_dict = {inputs: input_np}
      tf.global_variables_initializer().run()
      pre_pool_out = sess.run(pre_pool, feed_dict=feed_dict)
      self.assertListEqual(list(pre_pool_out.shape), [batch_size, 7, 7, 1024]) 
Example #11
Source File: inception_v2_test.py    From DeepLab_v3 with MIT License 6 votes vote down vote up
def testUnknownImageShape(self):
    tf.reset_default_graph()
    batch_size = 2
    height, width = 224, 224
    num_classes = 1000
    input_np = np.random.uniform(0, 1, (batch_size, height, width, 3))
    with self.test_session() as sess:
      inputs = tf.placeholder(tf.float32, shape=(batch_size, None, None, 3))
      logits, end_points = inception.inception_v2(inputs, num_classes)
      self.assertTrue(logits.op.name.startswith('InceptionV2/Logits'))
      self.assertListEqual(logits.get_shape().as_list(),
                           [batch_size, num_classes])
      pre_pool = end_points['Mixed_5c']
      feed_dict = {inputs: input_np}
      tf.global_variables_initializer().run()
      pre_pool_out = sess.run(pre_pool, feed_dict=feed_dict)
      self.assertListEqual(list(pre_pool_out.shape), [batch_size, 7, 7, 1024]) 
Example #12
Source File: inception_v3_test.py    From DeepLab_v3 with MIT License 6 votes vote down vote up
def testGlobalPoolUnknownImageShape(self):
    tf.reset_default_graph()
    batch_size = 1
    height, width = 330, 400
    num_classes = 1000
    input_np = np.random.uniform(0, 1, (batch_size, height, width, 3))
    with self.test_session() as sess:
      inputs = tf.placeholder(tf.float32, shape=(batch_size, None, None, 3))
      logits, end_points = inception.inception_v3(inputs, num_classes,
                                                  global_pool=True)
      self.assertListEqual(logits.get_shape().as_list(),
                           [batch_size, num_classes])
      pre_pool = end_points['Mixed_7c']
      feed_dict = {inputs: input_np}
      tf.global_variables_initializer().run()
      pre_pool_out = sess.run(pre_pool, feed_dict=feed_dict)
      self.assertListEqual(list(pre_pool_out.shape), [batch_size, 8, 11, 2048]) 
Example #13
Source File: inception_v1_test.py    From DeepLab_v3 with MIT License 6 votes vote down vote up
def testUnknownImageShape(self):
    tf.reset_default_graph()
    batch_size = 2
    height, width = 224, 224
    num_classes = 1000
    input_np = np.random.uniform(0, 1, (batch_size, height, width, 3))
    with self.test_session() as sess:
      inputs = tf.placeholder(tf.float32, shape=(batch_size, None, None, 3))
      logits, end_points = inception.inception_v1(inputs, num_classes)
      self.assertTrue(logits.op.name.startswith('InceptionV1/Logits'))
      self.assertListEqual(logits.get_shape().as_list(),
                           [batch_size, num_classes])
      pre_pool = end_points['Mixed_5c']
      feed_dict = {inputs: input_np}
      tf.global_variables_initializer().run()
      pre_pool_out = sess.run(pre_pool, feed_dict=feed_dict)
      self.assertListEqual(list(pre_pool_out.shape), [batch_size, 7, 7, 1024]) 
Example #14
Source File: test_method.py    From mmvec with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def test_equalize_sv(self):
        np.random.seed(1)
        tf.reset_default_graph()
        tf.set_random_seed(0)
        latent_dim = 2
        res_ranks, res_biplot = paired_omics(
            self.microbes, self.metabolites,
            epochs=1000, latent_dim=latent_dim,
            min_feature_count=1, learning_rate=0.1,
            equalize_biplot=True
        )
        # make sure the biplot is of the correct dimensions
        npt.assert_allclose(
            res_biplot.samples.shape,
            np.array([self.microbes.shape[0], latent_dim]))
        npt.assert_allclose(
            res_biplot.features.shape,
            np.array([self.metabolites.shape[0], latent_dim]))

        # make sure that the biplot has the correct ordering
        self.assertGreater(res_biplot.proportion_explained[0],
                           res_biplot.proportion_explained[1])
        self.assertGreater(res_biplot.eigvals[0],
                           res_biplot.eigvals[1]) 
Example #15
Source File: test_normal2dLikelihood.py    From decompose with MIT License 6 votes vote down vote up
def test_residuals(device, dtype):
    npdtype = dtype.as_numpy_dtype
    M, K, tau = (20, 30), 3, 0.1
    U = (tf.constant(np.random.normal(size=(K, M[0])).astype(npdtype)),
         tf.constant(np.random.normal(size=(K, M[1])).astype(npdtype)))
    noise = np.random.normal(size=M).astype(npdtype)
    data = tf.matmul(tf.transpose(U[0]), U[1]) + tf.constant(noise)

    lh = Normal2dLikelihood(M=M, K=K, tau=tau, dtype=dtype)
    lh.init(data=data)

    r = lh.residuals(U, data)

    assert(r.dtype == dtype)

    with tf.Session() as sess:
        sess.run(tf.global_variables_initializer())
        npr = sess.run(r)

    assert(np.allclose(noise.flatten(), npr, atol=1e-5, rtol=1e-5))
    tf.reset_default_graph() 
Example #16
Source File: inception_v2_test.py    From DeepLab_v3 with MIT License 6 votes vote down vote up
def testGlobalPoolUnknownImageShape(self):
    tf.reset_default_graph()
    batch_size = 1
    height, width = 250, 300
    num_classes = 1000
    input_np = np.random.uniform(0, 1, (batch_size, height, width, 3))
    with self.test_session() as sess:
      inputs = tf.placeholder(tf.float32, shape=(batch_size, None, None, 3))
      logits, end_points = inception.inception_v2(inputs, num_classes,
                                                  global_pool=True)
      self.assertTrue(logits.op.name.startswith('InceptionV2/Logits'))
      self.assertListEqual(logits.get_shape().as_list(),
                           [batch_size, num_classes])
      pre_pool = end_points['Mixed_5c']
      feed_dict = {inputs: input_np}
      tf.global_variables_initializer().run()
      pre_pool_out = sess.run(pre_pool, feed_dict=feed_dict)
      self.assertListEqual(list(pre_pool_out.shape), [batch_size, 8, 10, 1024]) 
Example #17
Source File: test_normal2dLikelihood.py    From decompose with MIT License 6 votes vote down vote up
def test_loss(device, dtype):
    npdtype = dtype.as_numpy_dtype
    M, K, tau = (20, 30), 3, 0.1
    U = (tf.constant(np.random.normal(size=(K, M[0])).astype(npdtype)),
         tf.constant(np.random.normal(size=(K, M[1])).astype(npdtype)))
    noise = np.random.normal(size=M).astype(npdtype)
    data = tf.matmul(tf.transpose(U[0]), U[1]) + tf.constant(noise)

    lh = Normal2dLikelihood(M=M, K=K, tau=tau, dtype=dtype)
    lh.init(data=data)

    loss = lh.loss(U, data)

    assert(loss.dtype == dtype)

    with tf.Session() as sess:
        sess.run(tf.global_variables_initializer())
        nploss = sess.run(loss)

    assert(np.allclose(np.sum(noise**2), nploss, atol=1e-5, rtol=1e-5))
    tf.reset_default_graph() 
Example #18
Source File: test_normal2dLikelihood.py    From decompose with MIT License 6 votes vote down vote up
def test_llh(device, dtype):
    npdtype = dtype.as_numpy_dtype
    M, K, tau = (20, 30), 3, 0.1
    U = (tf.constant(np.random.normal(size=(K, M[0])).astype(npdtype)),
         tf.constant(np.random.normal(size=(K, M[1])).astype(npdtype)))
    noise = np.random.normal(size=M).astype(npdtype)
    data = tf.matmul(tf.transpose(U[0]), U[1]) + tf.constant(noise)

    lh = Normal2dLikelihood(M=M, K=K, tau=tau, dtype=dtype)
    lh.init(data=data)

    llh = lh.llh(U, data)

    assert(llh.dtype == dtype)

    with tf.Session() as sess:
        sess.run(tf.global_variables_initializer())
        npllh = sess.run(llh)

    llhgt = np.sum(sp.stats.norm(loc=0., scale=1./np.sqrt(tau)).logpdf(noise))
    assert(np.allclose(llhgt, npllh, atol=1e-5, rtol=1e-5))
    tf.reset_default_graph() 
Example #19
Source File: test_normal2dLikelihood.py    From decompose with MIT License 6 votes vote down vote up
def test_update(device, f, updateType, dtype):
    npdtype = dtype.as_numpy_dtype
    M, K, tau = (20, 30), 3, 0.1
    npU = (np.random.normal(size=(K, M[0])).astype(npdtype),
           np.random.normal(size=(K, M[1])).astype(npdtype))
    U = (tf.constant(npU[0]), tf.constant(npU[1]))
    npnoise = np.random.normal(size=M).astype(npdtype)
    npdata = np.dot(npU[0].T, npU[1]) + npnoise
    data = tf.constant(npdata, dtype=dtype)

    lh = Normal2dLikelihood(M=M, K=K, tau=tau, updateType=updateType)
    lh.init(data=data)
    lh.noiseDistribution.update = MagicMock()
    residuals = tf.ones_like(data)
    lh.residuals = MagicMock(return_value=residuals)

    lh.update(U, data)

    if updateType == UpdateType.ALL:
        lh.residuals.assert_called_once()
        lh.noiseDistribution.update.assert_called_once()
    else:
        lh.residuals.assert_not_called()
        lh.noiseDistribution.update.assert_not_called()
    tf.reset_default_graph() 
Example #20
Source File: parallel_model.py    From dataiku-contrib with Apache License 2.0 6 votes vote down vote up
def build_model(x_train, num_classes):
        # Reset default graph. Keras leaves old ops in the graph,
        # which are ignored for execution but clutter graph
        # visualization in TensorBoard.
        tf.reset_default_graph()

        inputs = KL.Input(shape=x_train.shape[1:], name="input_image")
        x = KL.Conv2D(32, (3, 3), activation='relu', padding="same",
                      name="conv1")(inputs)
        x = KL.Conv2D(64, (3, 3), activation='relu', padding="same",
                      name="conv2")(x)
        x = KL.MaxPooling2D(pool_size=(2, 2), name="pool1")(x)
        x = KL.Flatten(name="flat1")(x)
        x = KL.Dense(128, activation='relu', name="dense1")(x)
        x = KL.Dense(num_classes, activation='softmax', name="dense2")(x)

        return KM.Model(inputs, x, "digit_classifier_model")

    # Load MNIST Data 
Example #21
Source File: inception_v3_test.py    From DeepLab_v3 with MIT License 6 votes vote down vote up
def testUnknownImageShape(self):
    tf.reset_default_graph()
    batch_size = 2
    height, width = 299, 299
    num_classes = 1000
    input_np = np.random.uniform(0, 1, (batch_size, height, width, 3))
    with self.test_session() as sess:
      inputs = tf.placeholder(tf.float32, shape=(batch_size, None, None, 3))
      logits, end_points = inception.inception_v3(inputs, num_classes)
      self.assertListEqual(logits.get_shape().as_list(),
                           [batch_size, num_classes])
      pre_pool = end_points['Mixed_7c']
      feed_dict = {inputs: input_np}
      tf.global_variables_initializer().run()
      pre_pool_out = sess.run(pre_pool, feed_dict=feed_dict)
      self.assertListEqual(list(pre_pool_out.shape), [batch_size, 8, 8, 2048]) 
Example #22
Source File: save_image.py    From ppo-lstm-parallel with MIT License 5 votes vote down vote up
def start(env):
    env = gym.make(env)
    frames = []
    MASTER_NAME = "master-0"
    IMAGE_PATH = "images/%s.gif" % env.spec.id
    tf.reset_default_graph()

    with tf.Session() as session:
        with tf.variable_scope(MASTER_NAME) as scope:
            env_opts = environments.get_env_options(env, False)
            policy = get_policy(env_opts, session)
            master_agent = PPOAgent(policy, session, MASTER_NAME, env_opts)

        saver = tf.train.Saver(max_to_keep=1)
        saver = tf.train.import_meta_graph(tf.train.latest_checkpoint("models/%s/" % env.spec.id) + ".meta")
        saver.restore(session, tf.train.latest_checkpoint("models/%s/" % env.spec.id))
        try:
            pass
        except:
            print("Failed to restore model, starting from scratch")
            session.run(tf.global_variables_initializer())

        global_step = 0
        while global_step < 1000:
            terminal = False
            s0 = env.reset()
            cum_rew = 0
            cur_hidden_state = master_agent.get_init_hidden_state()
            episode_count = 0
            while not terminal:
                episode_count += 1
                frames.append(env.render(mode='rgb_array'))
                action, h_out = master_agent.get_strict_sample(s0, cur_hidden_state)
                cur_hidden_state = h_out
                s0, r, terminal, _ = env.step(action)
                cum_rew += r
                global_step += 1
            print(episode_count, cum_rew)
        imageio.mimsave(IMAGE_PATH, frames, duration=1.0 / 60.0) 
Example #23
Source File: cartpole_a3c.py    From reinforcement_learning with MIT License 5 votes vote down vote up
def main():
  '''Example of A3C running on Cartpole environment'''
  tf.reset_default_graph()

  history = []

  with tf.device('/{}:0'.format(DEVICE)):
    sess = tf.Session()
    global_model = ac_net.AC_Net(
        STATE_SIZE,
        ACTION_SIZE,
        LEARNING_RATE,
        'global',
        n_h1=N_H1,
        n_h2=N_H2)
    workers = []
    for i in xrange(NUM_WORKERS):
      env = gym.make('CartPole-v0')
      env._max_episode_steps = 200
      workers.append(worker.Worker(env,
                                   state_size=STATE_SIZE, action_size=ACTION_SIZE,
                                   worker_name='worker_{}'.format(i), global_name='global',
                                   lr=LEARNING_RATE, gamma=GAMMA, t_max=T_MAX, sess=sess,
                                   history=history, n_h1=N_H1, n_h2=N_H2, logdir=LOG_DIR))

    sess.run(tf.global_variables_initializer())

    for workeri in workers:
      worker_work = lambda: workeri.work(NUM_EPISODES)
      thread = threading.Thread(target=worker_work)
      thread.start() 
Example #24
Source File: play.py    From ppo-lstm-parallel with MIT License 5 votes vote down vote up
def start(env):
    MASTER_NAME = "master-0"

    tf.reset_default_graph()

    with tf.Session() as session:
        with tf.variable_scope(MASTER_NAME) as scope:
            env_opts = environments.get_env_options(env, False)
            policy = get_policy(env_opts, session)
            master_agent = PPOAgent(policy, session, MASTER_NAME, env_opts)
        saver = tf.train.Saver(max_to_keep=1)
        saver = tf.train.import_meta_graph(tf.train.latest_checkpoint("models/%s/" % env) + ".meta")
        saver.restore(session, tf.train.latest_checkpoint("models/%s/" % env))
        try:
            pass
        except:
            print("Failed to restore model, starting from scratch")
            session.run(tf.global_variables_initializer())

        producer = environments.EnvironmentProducer(env, False)
        env = producer.get_new_environment()
        episode_count = 0
        cum_rew = 0
        while True:
            terminal = False
            s0 = env.reset()
            cur_hidden_state = master_agent.get_init_hidden_state()
            episode_count += 1
            cur_rew = 0
            while not terminal:
                env.render()
                action, h_out = master_agent.get_strict_sample(s0, cur_hidden_state)
                cur_hidden_state = h_out
                s0, r, terminal, _ = env.step(action)
                cum_rew += r
                cur_rew += r
            print("Ep: %s, cur_reward: %s reward: %s" % (episode_count, cur_rew, cum_rew / episode_count)) 
Example #25
Source File: tensorflow_cnn_from_scratch.py    From kaggle-code with MIT License 5 votes vote down vote up
def reset_graph(seed=42):
    tf.reset_default_graph()
    tf.set_random_seed(seed)
    np.random.seed(seed) 
Example #26
Source File: tf_nn_classification_bad.py    From kaggle-code with MIT License 5 votes vote down vote up
def reset_graph(seed=42):
    tf.reset_default_graph()
    tf.set_random_seed(seed)
    np.random.seed(seed) 
Example #27
Source File: insurance_tf_nn_classification_upsample.py    From kaggle-code with MIT License 5 votes vote down vote up
def reset_graph(seed=42):
    tf.reset_default_graph()
    tf.set_random_seed(seed)
    np.random.seed(seed) 
Example #28
Source File: insurance_tf_nn_classification_downsample.py    From kaggle-code with MIT License 5 votes vote down vote up
def reset_graph(seed=42):
    tf.reset_default_graph()
    tf.set_random_seed(seed)
    np.random.seed(seed) 
Example #29
Source File: embeddings_formatter.py    From embeddingsviz with MIT License 5 votes vote down vote up
def add_multiple_embeddings(log_dir, file_list, name_list):
    """ Creates the files necessary for the multiple embeddings

    :param log_dir: destination directory for the model and metadata (the one to which TensorBoard points)
    :param file_list: list of embeddings files
    :param name_list: names of the embeddings files
    :return:
    """
    # setup a TensorFlow session
    tf.reset_default_graph()
    sess = tf.InteractiveSession()
    sess.run(tf.global_variables_initializer())
    config = projector.ProjectorConfig()

    for i, file in enumerate(file_list):
        tensor_name = name_list[i]

        print('creating the embedding with the name ' + tensor_name)
        create_embeddings(sess, log_dir, embedding_file=file,
                          tensor_name=tensor_name)
        # create a TensorFlow summary writer
        summary_writer = tf.summary.FileWriter(log_dir, sess.graph)

        embedding_conf = config.embeddings.add()
        embedding_conf.tensor_name = tensor_name + ':0'
        embedding_conf.metadata_path = os.path.join(tensor_name + '_' + 'metadata.tsv')
        projector.visualize_embeddings(summary_writer, config)

        # save the model
        saver = tf.train.Saver()
        saver.save(sess, os.path.join(log_dir, tensor_name + '_' + "model.ckpt"))

    print('finished successfully!') 
Example #30
Source File: tf_nn_classification.py    From kaggle-code with MIT License 5 votes vote down vote up
def reset_graph(seed=42):
    tf.reset_default_graph()
    tf.set_random_seed(seed)
    np.random.seed(seed)