• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python tflearn.fully_connected函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tflearn.fully_connected函数的典型用法代码示例。如果您正苦于以下问题:Python fully_connected函数的具体用法?Python fully_connected怎么用?Python fully_connected使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了fully_connected函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: __init__

    def __init__(self, s_date, n_frame):
        self.n_epoch = 20
        prev_bd = int(s_date[:6])-1
        prev_ed = int(s_date[9:15])-1
        if prev_bd%100 == 0: prev_bd -= 98
        if prev_ed%100 == 0: prev_ed -= 98
        pred_s_date = "%d01_%d01" % (prev_bd, prev_ed)
        prev_model = '../model/tflearn/reg_l3_bn/big/%s' % pred_s_date
        self.model_dir = '../model/tflearn/reg_l3_bn/big/%s' % s_date

        tf.reset_default_graph()
        tflearn.init_graph(gpu_memory_fraction=0.1)
        input_layer = tflearn.input_data(shape=[None, 23*n_frame], name='input')
        dense1 = tflearn.fully_connected(input_layer, 400, name='dense1', activation='relu')
        dense1n = tflearn.batch_normalization(dense1, name='BN1')
        dense2 = tflearn.fully_connected(dense1n, 100, name='dense2', activation='relu')
        dense2n = tflearn.batch_normalization(dense2, name='BN2')
        dense3 = tflearn.fully_connected(dense2n, 1, name='dense3')
        output = tflearn.single_unit(dense3)
        regression = tflearn.regression(output, optimizer='adam', loss='mean_square',
                                metric='R2', learning_rate=0.001)
        self.estimators = tflearn.DNN(regression)
        if os.path.exists('%s/model.tfl' % prev_model):
            self.estimators.load('%s/model.tfl' % prev_model)
            self.n_epoch = 10
        if not os.path.exists(self.model_dir):
            os.makedirs(self.model_dir)
开发者ID:juwarny,项目名称:PyMLT,代码行数:27,代码来源:tflearn_regression.py


示例2: model_for_type

def model_for_type(neural_net_type, tile_size, on_band_count):
    """The neural_net_type can be: one_layer_relu,
                                   one_layer_relu_conv,
                                   two_layer_relu_conv."""
    network = tflearn.input_data(shape=[None, tile_size, tile_size, on_band_count])

    # NN architectures mirror ch. 3 of www.cs.toronto.edu/~vmnih/docs/Mnih_Volodymyr_PhD_Thesis.pdf
    if neural_net_type == "one_layer_relu":
        network = tflearn.fully_connected(network, 64, activation="relu")
    elif neural_net_type == "one_layer_relu_conv":
        network = conv_2d(network, 64, 12, strides=4, activation="relu")
        network = max_pool_2d(network, 3)
    elif neural_net_type == "two_layer_relu_conv":
        network = conv_2d(network, 64, 12, strides=4, activation="relu")
        network = max_pool_2d(network, 3)
        network = conv_2d(network, 128, 4, activation="relu")
    else:
        print("ERROR: exiting, unknown layer type for neural net")

    # classify as road or not road
    softmax = tflearn.fully_connected(network, 2, activation="softmax")

    # hyperparameters based on www.cs.toronto.edu/~vmnih/docs/Mnih_Volodymyr_PhD_Thesis.pdf
    momentum = tflearn.optimizers.Momentum(learning_rate=0.005, momentum=0.9, lr_decay=0.0002, name="Momentum")

    net = tflearn.regression(softmax, optimizer=momentum, loss="categorical_crossentropy")

    return tflearn.DNN(net, tensorboard_verbose=0)
开发者ID:trailbehind,项目名称:DeepOSM,代码行数:28,代码来源:single_layer_network.py


示例3: create_a3c_lstm_network

def create_a3c_lstm_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')

    # reshape l_hid3 to lstm usable shape (1, batch_size, 256)
    l_hid3_reshape = tf.reshape(l_hid3, [1, -1, 256])

    # have to custom make the lstm output here to use tf.nn.dynamic_rnn
    l_lstm = tflearn.BasicLSTMCell(256)
    # BasicLSTMCell lists state size as tuple so we need to pass tuple into dynamic_rnn
    lstm_state_size = tuple([[1, x] for x in l_lstm.state_size])
    # has to specifically be the same type tf.python.ops.rnn_cell.LSTMStateTuple
    from tensorflow.python.ops.nn import rnn_cell as _rnn_cell
    initial_lstm_state = _rnn_cell.LSTMStateTuple(tf.placeholder(tf.float32, shape=lstm_state_size[0], name='initial_lstm_state1'),
                                                  tf.placeholder(tf.float32, shape=lstm_state_size[1], name='initial_lstm_state2'))
    # dynamically get the sequence length
    sequence_length = tf.reshape(tf.shape(l_hid3)[0], [1])
    l_lstm4, new_lstm_state = tf.nn.dynamic_rnn(l_lstm, l_hid3_reshape,
                                                initial_state=initial_lstm_state, sequence_length=sequence_length,
                                                time_major=False, scope='lstm4')

    # reshape lstm back to (batch_size, 256)
    l_lstm4_reshape = tf.reshape(l_lstm4, [-1, 256])
    actor_out = tflearn.fully_connected(l_lstm4_reshape, output_num, activation='softmax', scope='actorout')
    critic_out = tflearn.fully_connected(l_lstm4_reshape, 1, activation='linear', scope='criticout')

    return actor_out, critic_out, initial_lstm_state, new_lstm_state
开发者ID:Islandman93,项目名称:reinforcepy,代码行数:28,代码来源:nstep_a3c_lstm.py


示例4: use_tflearn

def use_tflearn():
    import tflearn

    # Data loading and preprocessing
    import tflearn.datasets.mnist as mnist
    X, Y, testX, testY = mnist.load_data(one_hot=True)

    # Building deep neural network
    input_layer = tflearn.input_data(shape=[None, 784])
    dense1 = tflearn.fully_connected(input_layer, 64, activation='tanh',
                                     regularizer='L2', weight_decay=0.001)
    dropout1 = tflearn.dropout(dense1, 0.8)
    dense2 = tflearn.fully_connected(dropout1, 64, activation='tanh',
                                     regularizer='L2', weight_decay=0.001)
    dropout2 = tflearn.dropout(dense2, 0.8)
    softmax = tflearn.fully_connected(dropout2, 10, activation='softmax')

    # Regression using SGD with learning rate decay and Top-3 accuracy
    sgd = tflearn.SGD(learning_rate=0.1, lr_decay=0.96, decay_step=1000)
    top_k = tflearn.metrics.Top_k(3)
    net = tflearn.regression(softmax, optimizer=sgd, metric=top_k,
                             loss='categorical_crossentropy')

    # Training
    model = tflearn.DNN(net, tensorboard_verbose=0)
    model.fit(X, Y, n_epoch=20, validation_set=(testX, testY),
              show_metric=True, run_id="dense_model")
开发者ID:Emersonxuelinux,项目名称:2book,代码行数:27,代码来源:tools.py


示例5: deep_model

    def deep_model(self, wide_inputs, n_inputs, n_nodes=[100, 50], use_dropout=False):
        '''
        Model - deep, i.e. two-layer fully connected network model
        '''
        cc_input_var = {}
        cc_embed_var = {}
        flat_vars = []
        if self.verbose:
            print ("--> deep model: %s categories, %d continuous" % (len(self.categorical_columns), n_inputs))
        for cc, cc_size in self.categorical_columns.items():
            cc_input_var[cc] = tflearn.input_data(shape=[None, 1], name="%s_in" % cc,  dtype=tf.int32)
            # embedding layers only work on CPU!  No GPU implementation in tensorflow, yet!
            cc_embed_var[cc] = tflearn.layers.embedding_ops.embedding(cc_input_var[cc],    cc_size,  8, name="deep_%s_embed" % cc)
            if self.verbose:
                print ("    %s_embed = %s" % (cc, cc_embed_var[cc]))
            flat_vars.append(tf.squeeze(cc_embed_var[cc], squeeze_dims=[1], name="%s_squeeze" % cc))

        network = tf.concat(1, [wide_inputs] + flat_vars, name="deep_concat")
        for k in range(len(n_nodes)):
            network = tflearn.fully_connected(network, n_nodes[k], activation="relu", name="deep_fc%d" % (k+1))
            if use_dropout:
                network = tflearn.dropout(network, 0.5, name="deep_dropout%d" % (k+1))
        if self.verbose:
            print ("Deep model network before output %s" % network)
        network = tflearn.fully_connected(network, 1, activation="linear", name="deep_fc_output", bias=False)
        network = tf.reshape(network, [-1, 1])	# so that accuracy is binary_accuracy
        if self.verbose:
            print ("Deep model network %s" % network)
        return network
开发者ID:ALISCIFP,项目名称:tflearn,代码行数:29,代码来源:recommender_wide_and_deep.py


示例6: yn_net

def yn_net():
    net = tflearn.input_data(shape=[None, img_rows, img_cols, 1]) #D = 256, 256
    net = tflearn.conv_2d(net,nb_filter=8,filter_size=3, activation='relu', name='conv0.1')
    net = tflearn.conv_2d(net,nb_filter=8,filter_size=3, activation='relu', name='conv0.2')
    net = tflearn.max_pool_2d(net, kernel_size = [2,2], name='maxpool0') #D = 128, 128
    net = tflearn.dropout(net,0.75,name='dropout0')
    net = tflearn.conv_2d(net,nb_filter=16,filter_size=3, activation='relu', name='conv1.1')
    net = tflearn.conv_2d(net,nb_filter=16,filter_size=3, activation='relu', name='conv1.2')
    net = tflearn.max_pool_2d(net, kernel_size = [2,2], name='maxpool1') #D = 64,  64
    net = tflearn.dropout(net,0.75,name='dropout0')
    net = tflearn.conv_2d(net,nb_filter=32,filter_size=3, activation='relu', name='conv2.1')
    net = tflearn.conv_2d(net,nb_filter=32,filter_size=3, activation='relu', name='conv2.2')
    net = tflearn.max_pool_2d(net, kernel_size = [2,2], name='maxpool2') #D = 32 by 32
    net = tflearn.dropout(net,0.75,name='dropout0')
    net = tflearn.conv_2d(net,nb_filter=32,filter_size=3, activation='relu', name='conv3.1')
    net = tflearn.conv_2d(net,nb_filter=32,filter_size=3, activation='relu', name='conv3.2')
    net = tflearn.max_pool_2d(net, kernel_size = [2,2], name='maxpool3') #D = 16 by 16
    net = tflearn.dropout(net,0.75,name='dropout0')
#    net = tflearn.conv_2d(net,nb_filter=64,filter_size=3, activation='relu', name='conv4.1')
#    net = tflearn.conv_2d(net,nb_filter=64,filter_size=3, activation='relu', name='conv4.2')
#    net = tflearn.max_pool_2d(net, kernel_size = [2,2], name='maxpool4') #D = 8 by 8
#    net = tflearn.dropout(net,0.75,name='dropout0')
    net = tflearn.fully_connected(net, n_units = 128, activation='relu', name='fc1')
    net = tflearn.fully_connected(net, 2, activation='sigmoid')
    net = tflearn.regression(net, optimizer='adam', learning_rate=0.001)
    model = tflearn.DNN(net, tensorboard_verbose=1,tensorboard_dir='/tmp/tflearn_logs/')
    return model
开发者ID:bmalthi,项目名称:bnerveseg,代码行数:27,代码来源:train_yn.py


示例7: vgg16

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')

    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)

    return x
开发者ID:EddywardoFTW,项目名称:tflearn,代码行数:35,代码来源:vgg_network_finetuning.py


示例8: build_cnn_network

    def build_cnn_network(self, network):
        """ Build CNN network.

        Args:
            network: base network.

        Returns:
            model: CNN model.

        """
        print('Building CNN network.')
        # Convolutional network building
        network = tflearn.conv_2d(network, 32,
                            self.IMAGE_CHANNEL_NUM,
                          activation='relu')
        network = tflearn.max_pool_2d(network, 2)
        network = tflearn.conv_2d(network, 64,
                          self.IMAGE_CHANNEL_NUM,
                          activation='relu')
        network = tflearn.conv_2d(network, 64,
                          self.IMAGE_CHANNEL_NUM,
                          activation='relu')
        network = tflearn.max_pool_2d(network, 2)
        network = tflearn.fully_connected(
            network, 32 * 32, activation='relu')
        network = tflearn.dropout(network, 0.5)
        # Two category. positive or negative.
        network = tflearn.fully_connected(network, 2,
                                  activation='softmax')
        network = tflearn.regression(network, optimizer='adam',
                             loss='categorical_crossentropy',
                             learning_rate=0.001)
        print("CNN network built.")
        return network
开发者ID:NuitNoir,项目名称:MachineLearning,代码行数:34,代码来源:dnn_network.py


示例9: build_network

def build_network():
    network = tflearn.input_data(shape=[None, 2])
    network = tflearn.fully_connected(network, 64, activation='relu', regularizer='L2', weight_decay=0.001)
    network = tflearn.fully_connected(network, 1, activation='sigmoid')
    network = tflearn.regression(network, optimizer='sgd', learning_rate=0.3,
                           loss='mean_square')
    return network
开发者ID:belkale,项目名称:deeplearning_playground,代码行数:7,代码来源:circle_dl.py


示例10: create_nips_network

def create_nips_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')
    out = tflearn.fully_connected(l_hid3, output_num, scope='denseout')

    return out
开发者ID:Islandman93,项目名称:reinforcepy,代码行数:7,代码来源:tflow_util.py


示例11: create_a3c_network

def create_a3c_network(input_tensor, output_num):
    l_hid1 = tflearn.conv_2d(input_tensor, 16, 8, strides=4, activation='relu', padding='valid', scope='conv1')
    l_hid2 = tflearn.conv_2d(l_hid1, 32, 4, strides=2, activation='relu', padding='valid', scope='conv2')
    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
开发者ID:Islandman93,项目名称:reinforcepy,代码行数:8,代码来源:tflow_util.py


示例12: create_actor_network

 def create_actor_network(self): 
     inputs = tflearn.input_data(shape=[None, self.s_dim])
     net = tflearn.fully_connected(inputs, 400, activation='relu')
     net = tflearn.fully_connected(net, 300, activation='relu')
     # Final layer weights are init to Uniform[-3e-3, 3e-3]
     w_init = tflearn.initializations.uniform(minval=-0.003, maxval=0.003)
     out = tflearn.fully_connected(net, self.a_dim, activation='tanh', weights_init=w_init)
     scaled_out = tf.mul(out, self.action_bound) # Scale output to -action_bound to action_bound
     return inputs, out, scaled_out 
开发者ID:ataitler,项目名称:DQN,代码行数:9,代码来源:ddpg.py


示例13: simple_learn

 def simple_learn(self):
     tflearn.init_graph()
     net=tflearn.input_data(shape=[None,64,64,3])
     net=tflearn.fully_connected(net,64)
     net=tflearn.dropout(net,.5)
     net=tflearn.fully_connected(net,10,activation='softmax')
     net=tflearn.regression(net,optimizer='adam',loss='softmax_categorical_crossentropy')
     model = tflearn.DNN(net)
     model.fit(self.trainset,self.trainlabels)
开发者ID:Qrkchrm,项目名称:StateFarmShared,代码行数:9,代码来源:dataviewing.py


示例14: define_dnn_topology

def define_dnn_topology(input_num, first_layer, second_layer):
    tf.Graph().as_default()
    g = tflearn.input_data(shape=[None, input_num])
    g = tflearn.fully_connected(g, first_layer, activation='linear')
    g = tflearn.fully_connected(g, second_layer, activation='linear')
    g = tflearn.fully_connected(g, 1, activation='sigmoid')
    g = tflearn.regression(g, optimizer='sgd', learning_rate=2., loss='mean_square')
    tf.Graph().finalize() 
    return g 
开发者ID:kirai,项目名称:tensorflowplay,代码行数:9,代码来源:logicalopdnn.py


示例15: make_core_network

 def make_core_network(network):
     dense1 = tflearn.fully_connected(network, 64, activation='tanh',
                                      regularizer='L2', weight_decay=0.001, name="dense1")
     dropout1 = tflearn.dropout(dense1, 0.8)
     dense2 = tflearn.fully_connected(dropout1, 64, activation='tanh',
                                      regularizer='L2', weight_decay=0.001, name="dense2")
     dropout2 = tflearn.dropout(dense2, 0.8)
     softmax = tflearn.fully_connected(dropout2, 10, activation='softmax', name="softmax")
     return softmax
开发者ID:EddywardoFTW,项目名称:tflearn,代码行数:9,代码来源:weights_loading_scope.py


示例16: __init__

    def __init__(self,cluster,env,task_index,learning_rate=0.001):
        ''' Set-up network '''
        action_dim, discrete = check_action_space(env) # detect action space
        with tf.device(tf.train.replica_device_setter(worker_device="/job:worker/task:{}".format(task_index),cluster=cluster)):
            import tflearn # need to import within the tf.device statement for the tflearn.is_training variable to be shared !
            #tflearn.init_graph()
            #training = tf.get_variable(tflearn.get_training_mode().name,initializer=False)            
            #tf.get_variable(                  
            # Placeholders
            self.s = tf.placeholder("float32",np.array(np.append(None,env.observation_shape)))
            self.A = tf.placeholder("float32", (None,))
            self.V = tf.placeholder("float32", (None,))
            if discrete:
                self.a = tf.placeholder("int32", (None,)) # discrete action space
                self.a_one_hot = tf.one_hot(self.a,action_dim)
            else:
                self.a = tf.placeholder("float32", np.append(None,action_dim)) # continuous action space
            
            # Network
            ff = encoder_s(self.s,scope='encoder',reuse=False)
            self.p_out = tflearn.fully_connected(ff, n_units=action_dim, activation='softmax')
            self.v_out = tflearn.fully_connected(ff, n_units=1, activation='linear')
            
            ##### A3C #######        
            # Compute log_pi       
            log_probs = tf.log(tf.clip_by_value(self.p_out,1e-20,1.0)) # log pi
            if discrete:
                log_pi_given_a = tf.reduce_sum(log_probs * self.a_one_hot,reduction_indices=1)
            else: 
                raise(NotImplementedError)

            # Losses
            p_loss = -1*log_pi_given_a * self.A            
            entropy_loss = -1*tf.reduce_sum(self.p_out * log_probs,reduction_indices=1,name="entropy_loss") # policy entropy            
            v_loss = tf.nn.l2_loss(self.V - self.v_out, name="v_loss")
            loss1 = tf.add(p_loss,0.01*entropy_loss)
            self.loss = tf.add(loss1,v_loss)
    
            # Trainer
            optimizer = tf.train.AdamOptimizer(learning_rate)
            self.trainer = optimizer.minimize(self.loss)
                   
            # Global counter 
            #self.global_step = tf.get_variable('global_step', [], 
            #                    initializer = tf.constant_initializer(0), 
            #                    trainable = False)
            #self.global_step = tf.Variable(0)     
            #self.step_op = tf.Variable(0, trainable=False, name='step')
            #self.step_t = tf.placeholder("int32",(1,))
            #self.step_inc_op = self.step_op.assign_add(tf.squeeze(self.step_t), use_locking=True)
            
            # other stuff
            self.summary_placeholders, self.update_ops, self.summary_op = setup_summaries() # Summary operations
            self.saver = tf.train.Saver(max_to_keep=10)
            self.init_op = tf.initialize_all_variables()
            print('network initialized')
开发者ID:tmoer,项目名称:a3c-Tensorflow-OpenAIGym,代码行数:56,代码来源:Network.py


示例17: build_network

def build_network():
    network = tflearn.input_data(shape=[None, 2])
    network = tflearn.fully_connected(network, 64, activation='relu')
    network = dropout(network, 0.9)
    network = tflearn.fully_connected(network, 128, activation='relu')
    network = dropout(network, 0.9)
    network = tflearn.fully_connected(network, 2, activation='softmax')
    network = tflearn.regression(network, optimizer='sgd', learning_rate=0.1,
                           loss='categorical_crossentropy')
    return network
开发者ID:belkale,项目名称:deeplearning_playground,代码行数:10,代码来源:complicated1_dl.py


示例18: discriminator

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
开发者ID:EddywardoFTW,项目名称:tflearn,代码行数:10,代码来源:dcgan.py


示例19: run_XOR

def run_XOR():
    X = [[0., 0.], [0., 1.], [1., 0.], [1., 1.]]
    Y = [[0.], [1.], [1.], [0.]]

    g = tflearn.input_data(shape=[None, 2])
    g = tflearn.fully_connected(g, 128, activation='linear')
    g = tflearn.fully_connected(g, 128, activation='linear')
    g = tflearn.fully_connected(g, 1, activation='sigmoid')
    g = tflearn.regression(
        g, optimizer='sgd', learning_rate=2., loss='mean_square')

    train_model(g, X, Y)
开发者ID:kengz,项目名称:ai-notebook,代码行数:12,代码来源:logical.py


示例20: run_mnist

def run_mnist():
    X, Y, testX, testY = mnist.load_data(one_hot=True)
    g = tflearn.input_data(shape=[None, 784], name='input')
    g = tflearn.fully_connected(g, 128, name='dense1')
    g = tflearn.fully_connected(g, 256, name='dense2')
    g = tflearn.fully_connected(g, 10, activation='softmax', name='softmax')
    g = tflearn.regression(
        g, optimizer='adam',
        learning_rate=0.001,
        loss='categorical_crossentropy')

    if not os.path.isdir('models'):
        os.mkdir('models')
    m = tflearn.DNN(g, checkpoint_path='models/model.tfl.ckpt')
    m.fit(X, Y, n_epoch=1,
          validation_set=(testX, testY),
          show_metric=True,
          # Snapshot (save & evaluate) model every epoch.
          snapshot_epoch=True,
          # Snapshot (save & evalaute) model every 500 steps.
          snapshot_step=500,
          run_id='model_and_weights')
    m.save('models/mnist.tfl')

    # # load from file or ckpt and continue training
    # m.load('models/mnist.tfl')
    # # m.load('models/mnist.tfl.ckpt-500')
    # m.fit(X, Y, n_epoch=1,
    #       validation_set=(testX, testY),
    #       show_metric=True,
    #       # Snapshot (save & evaluate) model every epoch.
    #       snapshot_epoch=True,
    #       # Snapshot (save & evalaute) model every 500 steps.
    #       snapshot_step=500,
    #       run_id='model_and_weights')

    # retrieve layer by name, print weights
    dense1_vars = tflearn.variables.get_layer_variables_by_name('dense1')
    print('Dense1 layer weights:')
    print(m.get_weights(dense1_vars[0]))
    # or using generic tflearn function
    print('Dense1 layer biases:')
    with m.session.as_default():
        print(tflearn.variables.get_value(dense1_vars[1]))

    # or can even retrieve using attr `W` or `b`!
    print('Dense2 layer weights:')
    dense2 = tflearn.get_layer_by_name('dense2')
    print(dense2)
    print(m.get_weights(dense2.W))
    print('Dense2 layer biases:')
    with m.session.as_default():
        print(tflearn.variables.get_value(dense2.b))
开发者ID:kengz,项目名称:ai-notebook,代码行数:53,代码来源:weights_persistence.py



注:本文中的tflearn.fully_connected函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python tflearn.input_data函数代码示例发布时间:2022-05-27
下一篇:
Python tflearn.dropout函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap