Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def run():
X = tf.placeholder(shape=(None, 784), dtype=tf.float32)
Y = tf.placeholder(shape=(None, 10), dtype=tf.float32)
net = tf.reshape(X, [-1, 28, 28, 1]) # batch, height, width, chnl
# 32 filters, each of size 3(x3)
net = tflearn.conv_2d(net, 32, 3, activation='relu')
# pool kernel size 2, stride size default kernel soze
net = tflearn.max_pool_2d(net, 2)
# for "encourage some kind of inhibition and boost the neurons with
# relatively larger activations"
net = tflearn.local_response_normalization(net)
# The dropout method is introduced to prevent overfitting. At each training stage, individual nodes are either "dropped out" of the net with probability {\displaystyle 1-p} 1-p or kept with probability {\displaystyle p} p, so that a reduced network is left
# keep_prob=0.8
net = tflearn.dropout(net, 0.8)
# 64 filters
net = tflearn.conv_2d(net, 64, 3, activation='relu')
net = tflearn.max_pool_2d(net, 2)
net = tflearn.local_response_normalization(net)
net = tflearn.dropout(net, 0.8)
# FC
def discriminator(x, reuse=False):
with tf.variable_scope('Discriminator', reuse=reuse):
x = tflearn.conv_2d(x, 64, 5, activation='tanh')
x = tflearn.avg_pool_2d(x, 2)
x = tflearn.conv_2d(x, 128, 5, activation='tanh')
x = tflearn.avg_pool_2d(x, 2)
x = tflearn.fully_connected(x, 1024, activation='tanh')
x = tflearn.fully_connected(x, 2)
x = tf.nn.softmax(x)
return x
def create_a3c_network(input_tensor, output_num):
l_hid1 = tflearn.conv_2d(input_tensor, 16, 8, strides=4, activation='relu', scope='conv1', padding='valid')
l_hid2 = tflearn.conv_2d(l_hid1, 32, 4, strides=2, activation='relu', scope='conv2', padding='valid')
l_hid3 = tflearn.fully_connected(l_hid2, 256, activation='relu', scope='dense3')
actor_out = tflearn.fully_connected(l_hid3, output_num, activation='softmax', scope='actorout')
critic_out = tflearn.fully_connected(l_hid3, 1, activation='linear', scope='criticout')
return actor_out, critic_out, l_hid3
x = tflearn.conv_2d(input, 64, 3, activation='relu', scope='conv1_1')
x = tflearn.conv_2d(x, 64, 3, activation='relu', scope='conv1_2')
x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool1')
x = tflearn.conv_2d(x, 128, 3, activation='relu', scope='conv2_1')
x = tflearn.conv_2d(x, 128, 3, activation='relu', scope='conv2_2')
x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool2')
x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_1')
x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_2')
x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_3')
x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool3')
x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_1')
x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_2')
x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_3')
x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool4')
x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_1')
x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_2')
x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_3')
x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool5')
x = tflearn.fully_connected(x, 4096, activation='relu', scope='fc6')
x = tflearn.dropout(x, 0.5, name='dropout1')
x = tflearn.fully_connected(x, 4096, activation='relu', scope='fc7')
x = tflearn.dropout(x, 0.5, name='dropout2')
x = tflearn.fully_connected(x, num_class, activation='softmax', scope='fc8',
restore=False)
x = tflearn.conv_2d(x, 128, 3, activation='relu', scope='conv2_2')
x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool2')
x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_1')
x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_2')
x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_3')
x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool3')
x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_1')
x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_2')
x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_3')
x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool4')
x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_1')
x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_2')
x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_3')
x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool5')
x = tflearn.fully_connected(x, 4096, activation='relu', scope='fc6')
x = tflearn.dropout(x, 0.5, name='dropout1')
x = tflearn.fully_connected(x, 4096, activation='relu', scope='fc7')
x = tflearn.dropout(x, 0.5, name='dropout2')
x = tflearn.fully_connected(x, 1000, activation='softmax', scope='fc8')
return x
def run():
net = tflearn.input_data(shape=[None, 224, 224, 3])
net = tflearn.conv_2d(net, 64, 3, activation='relu')
net = tflearn.conv_2d(net, 64, 3, activation='relu')
net = tflearn.max_pool_2d(net, 2)
net = tflearn.conv_2d(net, 128, 3, activation='relu')
net = tflearn.conv_2d(net, 128, 3, activation='relu')
net = tflearn.max_pool_2d(net, 2)
net = tflearn.conv_2d(net, 256, 3, activation='relu')
net = tflearn.conv_2d(net, 256, 3, activation='relu')
net = tflearn.conv_2d(net, 256, 3, activation='relu')
net = tflearn.max_pool_2d(net, 2)
net = tflearn.conv_2d(net, 512, 3, activation='relu')
net = tflearn.conv_2d(net, 512, 3, activation='relu')
net = tflearn.conv_2d(net, 512, 3, activation='relu')
net = tflearn.max_pool_2d(net, 2)
net = tflearn.conv_2d(net, 512, 3, activation='relu')
net = tflearn.conv_2d(net, 512, 3, activation='relu')
net = tflearn.conv_2d(net, 512, 3, activation='relu')
net = tflearn.max_pool_2d(net, 2)
def vgg16(input, num_class):
x = tflearn.conv_2d(input, 64, 3, activation='relu', scope='conv1_1')
x = tflearn.conv_2d(x, 64, 3, activation='relu', scope='conv1_2')
x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool1')
x = tflearn.conv_2d(x, 128, 3, activation='relu', scope='conv2_1')
x = tflearn.conv_2d(x, 128, 3, activation='relu', scope='conv2_2')
x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool2')
x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_1')
x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_2')
x = tflearn.conv_2d(x, 256, 3, activation='relu', scope='conv3_3')
x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool3')
x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_1')
x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_2')
x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv4_3')
x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool4')
x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_1')
x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_2')
x = tflearn.conv_2d(x, 512, 3, activation='relu', scope='conv5_3')
x = tflearn.max_pool_2d(x, 2, strides=2, name='maxpool5')
def encoder(inputs,hidden_layer):
net = tflearn.conv_2d(inputs, 16, 3, strides=2)
net = tflearn.batch_normalization(net)
net = tflearn.elu(net)
print "========================"
print "enc-L1",net.get_shape()
print "========================"
net = tflearn.conv_2d(net, 16, 3, strides=1)
net = tflearn.batch_normalization(net)
net = tflearn.elu(net)
print "========================"
print "enc-L2",net.get_shape()
print "========================"
net = tflearn.conv_2d(net, 32, 3, strides=2)
net = tflearn.batch_normalization(net)
net = tflearn.elu(net)
print "========================"
print "enc-L3",net.get_shape()
print "========================"
net = tflearn.conv_2d(net, 32, 3, strides=1)
net = tflearn.batch_normalization(net)
net = tflearn.elu(net)
print "========================"
import tflearn
from rlflow.policies.f_approx import Network
from rlflow.algos.td import DQN
from rlflow.memories import ExperienceReplay
from rlflow.exploration import EpsilonGreedy
from rlflow.core.input import InputStreamDownsamplerProcessor, InputStreamSequentialProcessor, InputStreamProcessor
if __name__ == "__main__":
env = gym.make("Pong-v0")
with tf.Session() as sess:
input_tensor = tflearn.input_data(shape=(None, 84, 84, 4)) #tf_utils.get_input_tensor_shape(env))
net = tflearn.conv_2d(input_tensor, 16, 8, 4, activation='relu')
net = tflearn.conv_2d(net, 32, 4, 2, activation='relu')
net = tflearn.flatten(net)
net = tflearn.fully_connected(net, 1024, activation='relu')
net = tflearn.fully_connected(net, env.action_space.n, activation='linear')
network = Network(net,
sess,
Network.TYPE_DQN,
use_clone_net=True)
memory = ExperienceReplay(max_size=1000000)
egreedy = EpsilonGreedy(0.9, 0.1, 100000)
downsampler = InputStreamDownsamplerProcessor((84, 84), gray=True)
sequential = InputStreamSequentialProcessor(observations=4)
input_processor = InputStreamProcessor(processor_list=[downsampler, sequential])
def encoder(inputs,hidden_layer):
net = tflearn.conv_2d(inputs, 16, 3, strides=2)
net = tflearn.batch_normalization(net)
net = tflearn.elu(net)
print "========================"
print "enc-L1",net.get_shape()
print "========================"
net = tflearn.conv_2d(net, 16, 3, strides=1)
net = tflearn.batch_normalization(net)
net = tflearn.elu(net)
print "========================"
print "enc-L2",net.get_shape()
print "========================"
net = tflearn.conv_2d(net, 32, 3, strides=2)
net = tflearn.batch_normalization(net)
net = tflearn.elu(net)