InteractiveSession () # using InteractiveSession instead of Session to test network in separate cell sess. argmax ( output_logits, axis = 1, name = 'predictions' ) # Initializing the variables init = tf. float32 ), name = 'accuracy' ) # Network predictions cls_prediction = tf. argmax ( y, 1 ), name = 'correct_pred' ) accuracy = tf. variable_scope ( 'Accuracy' ): correct_prediction = tf. AdamOptimizer ( learning_rate = learning_rate, name = 'Adam-op' ). variable_scope ( 'Optimizer' ): optimizer = tf. softmax_cross_entropy_with_logits ( labels = y, logits = output_logits ), name = 'loss' ) with tf. float32, shape =, name = 'Y' ) fc1 = fc_layer ( x, h1, 'Hidden_layer', use_relu = True ) output_logits = fc_layer ( fc1, n_classes, 'Output_layer', use_relu = False ) # Define the loss function, optimizer, and accuracy with tf. # Create graph # Placeholders for inputs (x), outputs(y) with tf. matmul ( x, W ) layer += b if use_relu : layer = tf. get_shape () W = weight_variable ( name, shape = ) b = bias_variable ( name, ) layer = tf. float32, initializer = initial ) def fc_layer ( x, num_units, name, use_relu = True ): """ Create a fully-connected layer :param x: input from previous layer :param num_units: number of hidden units in the fully-connected layer :param name: layer name :param use_relu: boolean to add ReLU non-linearity (or not) :return: The output array """ with tf. float32, shape = shape, initializer = initer ) def bias_variable ( name, shape ): """ Create a bias variable with appropriate initialization :param name: bias variable name :param shape: bias variable shape :return: initialized bias variable """ initial = tf. truncated_normal_initializer ( stddev = 0.01 ) return tf. # weight and bais wrappers def weight_variable ( name, shape ): """ Create a weight variable with appropriate initialization :param name: weight name :param shape: weight shape :return: initialized weight variable """ initer = tf.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |