def sg_argmax(tensor, opt): r"""Returns the indices of the maximum values along the specified dimension. See `tf.argmax()` in tensorflow. Args: tensor: A `Tensor` (automatically given by chain). opt: dim: Target dimension. Default is the last one. name: If provided, replace current tensor's name. Returns: A `Tensor`. """ opt += tf.sg_opt(dim=tensor.get_shape().ndims - 1) return tf.argmax(tensor, opt.dim, opt.name)
def sg_argmax(tensor, opt): opt += tf.sg_opt(dim=tensor.get_shape().ndims - 1) return tf.argmax(tensor, opt.dim, opt.name)
W = tf.Variable( tf.random_normal([n_hidden_units_three, num_classes], mean=0, stddev=sd)) b = tf.Variable(tf.random_normal([num_classes], mean=0, stddev=sd)) with tf.name_scope('out'): y_ = tf.nn.softmax(tf.matmul(h_3, W) + b, name="out") init = tf.global_variables_initializer() cost_function = tf.reduce_mean( -tf.reduce_sum(Y * tf.log(y_), reduction_indices=[1])) #optimizer = tf.train.RMSPropOptimizer(learning_rate,decay=0.9,momentum=0.9,centered=True).minimize(cost_function) optimizer = tf.train.GradientDescentOptimizer(learning_rate).minimize( cost_function) correct_prediction = tf.equal(tf.argmax(y_, 1), tf.argmax(Y, 1)) accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32)) cost_history = np.empty(shape=[1], dtype=float) acc_history = np.empty(shape=[1], dtype=float) t_cost_history = np.empty(shape=[1], dtype=float) t_acc_history = np.empty(shape=[1], dtype=float) y_true, y_pred = None, None with tf.Session() as session: session.run(init) saver = tf.train.Saver() for epoch in range(epochs): for batch in range(int(db_size / batchsize)): indices = get_indices(batchsize) feed = data_tools.next_minibatch(indices, db)