コード例 #1
0
ファイル: agent.py プロジェクト: 23156145525/icodoom
    def make_fcnet(self):
        n_ffnet_inputs = self.n_ffnet_input
        n_ffnet_outputs = self.n_ffnet_output

        y_image = self.fcnet_input

        print("FCNET: Inputs: ", n_ffnet_inputs, " outputs: ", n_ffnet_outputs)

        W_fc1 = my_ops.weight_variable([n_ffnet_inputs, 40], 0.1)
        b_fc1 = my_ops.bias_variable([40])

        W_fc2 = my_ops.weight_variable([40, 10], 0.1)
        b_fc2 = my_ops.bias_variable([10])

        W_fc3 = my_ops.weight_variable([10, 1], 0.1)
        b_fc3 = my_ops.bias_variable([1])

        h1 = tf.tanh(tf.matmul(y_image, W_fc1) + b_fc1)
        h2 = tf.tanh(tf.matmul(h1, W_fc2) + b_fc2)
        self.y_fc = tf.tanh(tf.matmul(h2, W_fc3) + b_fc3)

        self.fcloss = tf.squared_difference(self.y_fc, self.fcnet_target)
        self.fcnet_train_step = tf.train.AdamOptimizer(
            self.learning_rate).minimize(self.fcloss)
        self.fcaccuracy = tf.reduce_mean(self.fcloss)
コード例 #2
0
ファイル: agent1.py プロジェクト: 23156145525/icodoom
    def make_ffnet(self):


        n_ffnet_inputs = self.n_ffnet_input
        n_ffnet_outputs = self.n_ffnet_output
        print ("FFNET: in: ", n_ffnet_inputs, " hid: ", self.n_ffnet_hidden, " out: ", n_ffnet_outputs)


        W_layer1 = my_ops.weight_variable([n_ffnet_inputs, self.n_ffnet_hidden[0]])
        b_layer1 = my_ops.bias_variable([self.n_ffnet_hidden[0]])

        W_layer2 = my_ops.weight_variable([self.n_ffnet_hidden[0], self.n_ffnet_hidden[1]])
        b_layer2 = my_ops.bias_variable([self.n_ffnet_hidden[1]])

        W_layer3 = my_ops.weight_variable([self.n_ffnet_hidden[1], n_ffnet_outputs])
        b_layer3 = my_ops.bias_variable([n_ffnet_outputs])

        h_1 = tf.nn.relu(tf.matmul(self.ffnet_input, W_layer1) + b_layer1)
        h_2 = tf.nn.relu(tf.matmul(h_1, W_layer2) + b_layer2)

        # dropout
        #print("output shape: ", self.ffnet_output.get_shape(), "target shape: ", self.ffnet_target.get_shape())
        #print("W3: ", W_layer3.get_shape(), " bias3: ", b_layer3.get_shape())

        self.ffnet_output = tf.matmul(h_2, W_layer3) + b_layer3
        #print("output shape: ", self.ffnet_output.get_shape(), "target shape: ", self.ffnet_target.get_shape())
        #print("W3: ", W_layer3.get_shape(), " bias3: ", b_layer3.get_shape())

        self.loss = tf.squared_difference(self.ffnet_output, self.ffnet_target)

        self.ffnet_train_step = tf.train.AdamOptimizer(self.learning_rate).minimize(self.loss)

        self.accuracy = tf.reduce_mean(self.loss)
コード例 #3
0
    def __init__(self, name, config, is_train):
        self.name = name
        self.is_train = is_train
        self.reuse = None

        with tf.variable_scope(self.name, reuse=self.reuse):
            G_W1 = utils.weight_variable([3, 3, 1, 32], name="G_W1")
            G_b1 = utils.bias_variable([32], name="G_b1")

            G_W2 = utils.weight_variable([3, 3, 32, 64], name="G_W2")
            G_b2 = utils.bias_variable([64], name="G_b2")

            G_W3 = utils.weight_variable([3, 3, 64, 64], name="G_W3")
            G_b3 = utils.bias_variable([64], name="G_b3")

            G_W4 = utils.weight_variable([3, 3, 64, 128], name="G_W4")
            G_b4 = utils.bias_variable([128], name="G_b4")

            G_W5 = utils.weight_variable([3, 3, 128, 128], name="G_W5")
            G_b5 = utils.bias_variable([128], name="G_b5")

            G_W6 = utils.weight_variable([3, 3, 128, 128], name="G_W6")
            G_b6 = utils.bias_variable([128], name="G_b6")

            G_W7 = utils.weight_variable([3, 3, 128, 64], name="G_W7")
            G_b7 = utils.bias_variable([64], name="G_b7")

            G_W8 = utils.weight_variable([1, 1, 64, 32], name="G_W8")
            G_b8 = utils.bias_variable([32], name="G_b8")

            G_W9 = utils.weight_variable([3, 3, 32, config.ClusterNo],
                                         name="G_W9")
            G_b9 = utils.bias_variable([config.ClusterNo], name="G_b9")

            self.Param = {
                'G_W1': G_W1,
                'G_b1': G_b1,
                'G_W2': G_W2,
                'G_b2': G_b2,
                'G_W3': G_W3,
                'G_b3': G_b3,
                'G_W4': G_W4,
                'G_b4': G_b4,
                'G_W5': G_W5,
                'G_b5': G_b5,
                'G_W6': G_W6,
                'G_b6': G_b6,
                'G_W7': G_W7,
                'G_b7': G_b7,
                'G_W8': G_W8,
                'G_b8': G_b8,
                'G_W9': G_W9,
                'G_b9': G_b9
            }

        if self.reuse is None:
            self.var_list = tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES,
                                              scope=self.name)
            self.saver = tf.train.Saver(self.var_list)
            self.reuse = True
コード例 #4
0
 def __init__(self, name, config, is_train):
   self.name = name
   self.is_train = is_train
   self.reuse = None
   
   with tf.variable_scope(self.name, reuse=self.reuse):
       G_W1 = utils.weight_variable([3, 3, 1, 32], name="G_W1")
       G_b1 = utils.bias_variable([32], name="G_b1")
       
       G_W2 = utils.weight_variable([3, 3, 32, 64], name="G_W2")
       G_b2 = utils.bias_variable([64], name="G_b2")
       
       G_W3 = utils.weight_variable([3, 3, 64, 64], name="G_W3")
       G_b3 = utils.bias_variable([64], name="G_b3")
       
       G_W4 = utils.weight_variable([3, 3, 64, 128], name="G_W4")
       G_b4 = utils.bias_variable([128], name="G_b4")
       
       G_W5 = utils.weight_variable([3, 3, 128, 128], name="G_W5")
       G_b5 = utils.bias_variable([128], name="G_b5")
       
       G_W6 = utils.weight_variable([3, 3, 128, 128], name="G_W6") 
       G_b6 = utils.bias_variable([128], name="G_b6")
       
       G_W7 = utils.weight_variable([3, 3, 128, 64], name="G_W7") 
       G_b7 = utils.bias_variable([64], name="G_b7")
       
       G_W8 = utils.weight_variable([1, 1, 64, 32], name="G_W8")
       G_b8 = utils.bias_variable([32], name="G_b8")
       
       G_W9 = utils.weight_variable([3, 3, 32, config.ClusterNo], name="G_W9")
       G_b9 = utils.bias_variable([config.ClusterNo], name="G_b9")
       
       self.Param = {'G_W1':G_W1, 'G_b1':G_b1, 
                'G_W2':G_W2, 'G_b2':G_b2,  
                'G_W3':G_W3, 'G_b3':G_b3, 
                'G_W4':G_W4, 'G_b4':G_b4, 
                'G_W5':G_W5, 'G_b5':G_b5, 
                'G_W6':G_W6, 'G_b6':G_b6, 
                'G_W7':G_W7, 'G_b7':G_b7, 
                'G_W8':G_W8, 'G_b8':G_b8, 
                'G_W9':G_W9, 'G_b9':G_b9 }
     
   if self.reuse is None:
         self.var_list = tf.get_collection(tf.GraphKeys.GLOBAL_VARIABLES, scope=self.name)
         self.saver = tf.train.Saver(self.var_list)
         self.reuse = True         
コード例 #5
0
ファイル: agent1.py プロジェクト: 23156145525/icodoom
    def make_convnet(self):
        n_ffnet_inputs = self.n_ffnet_input
        n_ffnet_outputs = self.n_ffnet_output

        print("COVNET: Inputs: ", n_ffnet_inputs, " outputs: ", n_ffnet_outputs)

        with tf.name_scope('reshape'):
            x_image = tf.reshape(self.covnet_input, [-1, self.resolution[0], self.resolution[1], 1])

        with tf.name_scope('conv1'):
            W_conv1 = my_ops.weight_variable([5, 5, 1, 32])
            b_conv1 = my_ops.bias_variable([32])
            h_conv1 = tf.nn.relu(my_ops.conv2d(x_image, W_conv1) + b_conv1)

        with tf.name_scope('pool1'):
            h_pool1 = my_ops.max_pool_2x2(h_conv1)

        with tf.name_scope('conv2'):
            W_conv2 = my_ops.weight_variable([5, 5, 32, 64])
            b_conv2 = my_ops.bias_variable([64])
            h_conv2 = tf.nn.relu(my_ops.conv2d(h_pool1, W_conv2) + b_conv2)

        with tf.name_scope('pool2'):
            h_pool2 = my_ops.max_pool_2x2(h_conv2)

        with tf.name_scope('fc1'):
            W_fc1 = my_ops.weight_variable([int(self.resolution[0]/4) * int(self.resolution[1]/4) * 64, 64])
            b_fc1 = my_ops.bias_variable([64])

            h_pool2_flat = tf.reshape(h_pool2, [-1, int(self.resolution[0]/4) * int(self.resolution[1]/4) * 64])
            h_fc1 = tf.nn.relu(tf.matmul(h_pool2_flat, W_fc1) + b_fc1)

        # single output:
        with tf.name_scope('fc2'):
            W_fc2 = my_ops.weight_variable([64, 1])
            b_fc2 = my_ops.bias_variable([1])

        self.y_conv = tf.tanh(tf.matmul(h_fc1, W_fc2) + b_fc2)
        self.covloss = tf.squared_difference(self.y_conv, self.covnet_target)
        self.covnet_train_step = tf.train.AdamOptimizer(self.learning_rate).minimize(self.covloss)
        self.covaccuracy = tf.reduce_mean(self.covloss)
コード例 #6
0
ファイル: main.py プロジェクト: royanshul/easy-tensorflow
batch_size = 100  # Training batch size
display_freq = 100  # Frequency of displaying the training results

# Network Parameters
num_input = 28  # MNIST data input (img shape: 28*28)
timesteps = 28  # Timesteps
num_hidden_units = 128  # Number of hidden units of the RNN
n_classes = 10  # Number of classes, one class per digit

# Create the graph for the linear model
# Placeholders for inputs (x) and outputs(y)
x = tf.placeholder(tf.float32, shape=[None, timesteps, num_input], name='X')
y = tf.placeholder(tf.float32, shape=[None, n_classes], name='Y')

# create weight matrix initialized randomely from N~(0, 0.01)
W = weight_variable(shape=[num_hidden_units, n_classes])

# create bias vector initialized as zero
b = bias_variable(shape=[n_classes])

output_logits = RNN(x, W, b, timesteps, num_hidden_units)
y_pred = tf.nn.softmax(output_logits)

# Model predictions
cls_prediction = tf.argmax(output_logits, axis=1, name='predictions')

# Define the loss function, optimizer, and accuracy
loss = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(
    labels=y, logits=output_logits),
                      name='loss')
optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate,
コード例 #7
0
ファイル: agent.py プロジェクト: 23156145525/icodoom
    def make_convnet(self):
        #         # self.resolution is [width, height]
        #         x_image = tf.reshape(self.covnet_input, [-1, self.resolution[0], self.resolution[1], 1])
        #
        #         n_features_maps = 20
        #         filter_width = int(2)
        #         filter_height = int(2)
        #
        #         W_conv1 = my_ops.weight_variable([filter_width, filter_height, 1, n_features_maps], 0.001)
        #         b_conv1 = my_ops.bias_variable([n_features_maps])
        #         h_conv1 = tf.nn.tanh(my_ops.conv2d(x_image, W_conv1) + b_conv1)
        #
        #         h_pool1 = my_ops.max_pool_2x2(h_conv1)
        # #        h_pool1 = h_conv1
        #
        #         W_fc1 = my_ops.weight_variable([int(self.resolution[0]/2) * int(self.resolution[1]/2) * n_features_maps, 20], 0.001)
        #         b_fc1 = my_ops.bias_variable([20])
        #
        #         h_pool1_flat = tf.reshape(h_pool1, [-1, int(self.resolution[0]/2) * int(self.resolution[1]/2) * n_features_maps])
        #         h_fc1 = tf.nn.tanh(tf.matmul(h_pool1_flat, W_fc1) + b_fc1)
        #
        #         # single output:
        #         W_fc2 = my_ops.weight_variable([20, 1], 0.01)
        #         b_fc2 = my_ops.bias_variable([1])
        #
        #         self.y_conv = tf.tanh(tf.matmul(h_fc1, W_fc2) + b_fc2)
        #
        #         self.covloss = tf.squared_difference(self.y_conv, self.covnet_target)
        #         self.covnet_train_step = tf.train.AdamOptimizer(self.learning_rate).minimize(self.covloss)
        #         self.covaccuracy = tf.reduce_mean(self.covloss)

        with tf.name_scope('reshape'):
            x_image = tf.reshape(
                self.covnet_input,
                [-1, self.resolution[0], self.resolution[1], 1])

        # First convolutional layer - maps one grayscale image to 32 feature maps.
        with tf.name_scope('conv1'):
            W_conv1 = my_ops.weight_variable([5, 5, 1, 8], 0.1)
            b_conv1 = my_ops.bias_variable([8])
            h_conv1 = tf.nn.relu(my_ops.conv2d(x_image, W_conv1) + b_conv1)

        # Pooling layer - downsamples by 2X.
        with tf.name_scope('pool1'):
            h_pool1 = my_ops.max_pool_2x2(h_conv1)

        # Second convolutional layer -- maps 32 feature maps to 64.
        with tf.name_scope('conv2'):
            W_conv2 = my_ops.weight_variable([5, 5, 8, 8], 0.1)
            b_conv2 = my_ops.bias_variable([8])
            h_conv2 = tf.nn.relu(my_ops.conv2d(h_pool1, W_conv2) + b_conv2)

        # Second pooling layer.
        with tf.name_scope('pool2'):
            h_pool2 = my_ops.max_pool_2x2(h_conv2)

        # Fully connected layer 1 -- after 2 round of downsampling, our 28x28 image
        # is down to 7x7x64 feature maps -- maps this to 1024 features.
        with tf.name_scope('fc1'):
            W_fc1 = my_ops.weight_variable([
                int(self.resolution[0] / 4) * int(self.resolution[1] / 4) * 8,
                10
            ], 0.001)
            b_fc1 = my_ops.bias_variable([10])

            h_pool2_flat = tf.reshape(h_pool2, [
                -1,
                int(self.resolution[0] / 4) * int(self.resolution[1] / 4) * 8
            ])
            h_fc1 = tf.nn.relu(tf.matmul(h_pool2_flat, W_fc1) + b_fc1)

        # Map the 1024 features to 10 classes, one for each digit
        with tf.name_scope('fc2'):
            W_fc2 = my_ops.weight_variable([10, 1], 0.1)
            b_fc2 = my_ops.bias_variable([1])

            self.y_conv = tf.tanh(tf.matmul(h_fc1, W_fc2) + b_fc2)
            self.covloss = tf.squared_difference(self.y_conv,
                                                 self.covnet_target)
            self.covnet_train_step = tf.train.AdamOptimizer(
                self.learning_rate).minimize(self.covloss)
            self.covaccuracy = tf.reduce_mean(self.covloss)