Example #1
0
def self_test():
    """Test the translation model."""
    with tf.Session() as sess:
        print("Self-test for neural translation model.")
        # Create model with vocabularies of 10, 2 small buckets, 2 layers of 32.
        model = seq2seq_model.Seq2SeqModel(10,
                                           10, [(3, 3), (6, 6)],
                                           32,
                                           2,
                                           5.0,
                                           32,
                                           0.3,
                                           0.99,
                                           num_samples=8)
        sess.run(tf.global_variables_initialize())

        # Fake data set for both the (3, 3) and (6, 6) bucket.
        data_set = ([([1, 1], [2, 2]), ([3, 3], [4]),
                     ([5], [6])], [([1, 1, 1, 1, 1], [2, 2, 2, 2, 2]),
                                   ([3, 3, 3], [5, 6])])
        for _ in xrange(5):  # Train the fake model for 5 steps.
            bucket_id = random.choice([0, 1])
            encoder_inputs, decoder_inputs, target_weights = model.get_batch(
                data_set, bucket_id)
            model.step(sess, encoder_inputs, decoder_inputs, target_weights,
                       bucket_id, False)
Example #2
0
                0,
                [self.actions[rindex] -
                 1]] = self.rewards[rindex] + self.discount * next_state_max_Q

            inputs[i] = current_input_state
            targets[i] = target

        return inputs, targets


memory = ReplayMemory(env.nx, env.ny, max_memory, gamma)

win_cnt = 0

sess = tf.InteractiveSession()
sess.run(tf.global_variables_initialize())
saver = tf.train.Saver()

for episode in range(n_episodes):
    err = 0
    s = env.reset()
    for t in range(max_steps):
        if np.random.rand() < epsilon:
            a = np.random.randint(env.na)  # random action
        else:
            q = sess.run(
                y_hat,
                feed_dict={x: np.reshape(s, [1, env.ny, env.nx, env.nf])})
            a = np.random.choice(np.where(q[0] == np.max(q))[0])
        sn, r, terminal, _, _, _, _, _, _, _, _ = env.run(
            a - 1)  # action to take is -1, 0, 1
Example #3
0
def style_loss(sess,model):
	
	pass

def content_loss(sess,model):
	
	pass

IMAGE_WIDTH=248
IMAGE_HEIGHT=248

learning_rate=0.1
total_loss=style_weight*style_loss(sess,model)+contents_weight*content_loss(sess,model)
optimizer=tf.train.AdamOptimizer(2.0)
train_step=optimizer.minimize(total_loss)
init=tf.global_variables_initialize()
with tf.Session() as sess:
	sess.run(init)
	sess.
def train():
	pass
	# The network has two loss functions
	# one is style loss and the other is contents loss
	# 
	contents_image=np.fromfile(contents_image_filename)
	
	weights={
	


if __name__=='__main__':
Example #4
0
 def initialize(self):
     self.sess = tf.Session()
     self.sess.run(tf.global_variables_initialize())