Esempio n. 1
0
def normalize_columns_together( headers,d ):
	#normalizes all the data so the min maps to 0 and the max maps to 1
	data = d.get_data(headers)
	if data.size > 0:
		norm = data - data.min()
		if data.max() != 0:
			norm = norm/data.max()
		return norm
def highlight_max(data, color='#0e5c99'):
    '''
    highlight the maximum in a Series or DataFrame
    '''
    attr = 'background-color: {}'.format(color)
    if data.ndim == 1:  # Series from .apply(axis=0) or axis=1
        is_max = data == data.max()
        return [attr if v else '' for v in is_max]
    else:  # from .apply(axis=None)
        is_max = data == data.max().max()
        return pd.DataFrame(np.where(is_max, attr, ''),
                            index=data.index, columns=data.columns)
Esempio n. 3
0
def visualize_data(data,
                   padsize=1,
                   padval=0,
                   cmap="gray",
                   image_size=(10, 10)):
    data -= data.min()
    data /= data.max()

    # force the number of filters to be square
    n = int(np.ceil(np.sqrt(data.shape[0])))
    padding = ((0, n**2 - data.shape[0]), (0, padsize),
               (0, padsize)) + ((0, 0), ) * (data.ndim - 3)
    data = np.pad(data,
                  padding,
                  mode='constant',
                  constant_values=(padval, padval))

    # tile the filters into an image
    data = data.reshape((n, n) + data.shape[1:]).transpose(
        (0, 2, 1, 3) + tuple(range(4, data.ndim + 1)))
    data = data.reshape((n * data.shape[1], n * data.shape[3]) +
                        data.shape[4:])

    #plt.figure(figsize=image_size)
    plt.imshow(data, cmap=cmap)
    plt.show()
    plt.axis('off')
Esempio n. 4
0
def generateDataImage(data,metadata,imgname):
    fig = plt.figure(figsize=(8,4))
    ax = fig.add_subplot(121)
    ax.imshow(data,origin='lower',cmap=cm.jet)
    ax2 = fig.add_subplot(122)
    vmax = data.max()
    if vmax < 1: vmax=1
    ax2.imshow(data,origin='lower',cmap=cm.jet,norm=LogNorm(vmin=1, vmax=vmax))
    #plt.colorbar(data,ax=ax2,norm=LogNorm(vmin=1))
    fig.savefig(imgname)
Esempio n. 5
0
def draw_img_rgb(data):
    size = 96
    n = data.shape[0]
    plt.figure(figsize=(n*2, 2))
    data /= data.max()
    cnt = 1
    for idx in np.arange(n):
        plt.subplot(1, n, cnt)
        tmp = data[idx,:,:,:].transpose(1,2,0)
        plt.imshow(tmp)
        plt.tick_params(labelbottom="off")
        plt.tick_params(labelleft="off")
        cnt+=1
    plt.show()
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--epoch', type=int, default=200, help='# of Epochs')
    parser.add_argument('--learn',
                        type=float,
                        default=1e-1,
                        help='learning rate')
    parser.add_argument('--photo', type=int, default=1, help='photo index')

    FLAGS = parser.parse_args()
    NEpochs = FLAGS.epoch
    learningRate = FLAGS.learn

    x = tf.Variable(tf.zeros([1, imageSize], dtype=tf.float32))
    y = FLAGS.photo
    w = tf.placeholder(tf.float32, shape=(imageSize, NClasses))
    b = tf.placeholder(tf.float32, shape=(NClasses))

    with tf.Session() as sess:
        sess.run(tf.global_variables_initializer())
        new_saver = tf.train.import_meta_graph(model_dir + 'model.meta')
        new_saver.restore(sess, tf.train.latest_checkpoint(model_dir))
        graph = tf.get_default_graph()
        weights = sess.run(graph.get_tensor_by_name("weights:0"))
        biases = sess.run(graph.get_tensor_by_name("biases:0"))

        prediction = tf.nn.softmax(tf.matmul(x, w) + b)
        loss = 1 - prediction[0][y]
        optimizer = tf.train.GradientDescentOptimizer(learningRate).minimize(
            loss)
        for epoch in range(NEpochs):
            _, l = sess.run([optimizer, loss],
                            feed_dict={
                                w: weights,
                                b: biases
                            })
            print("Epoch: %01d loss: %.4f" % (epoch + 1, l))

        data = np.asarray(sess.run(x), dtype = np.float32).\
                          reshape([-1, imageHeight, imageWidth])[0]
        data_rescaled = (255.0 / data.max() * data).astype(np.uint8)
        plt.imshow(np.asarray(sess.run(x)).reshape(
            [-1, imageHeight, imageWidth])[0],
                   cmap='gray')
        #        plt.savefig('inversion/test_'+str(y)+'.png')
        plt.savefig('/home/ubuntu/test_' + str(y) + '.png')
Esempio n. 7
0
def visualize_data(data, padsize=1, padval=0, cmap="gray", image_size=(10,10)):
    data -= data.min()
    data /= data.max()

    # force the number of filters to be square
    n = int(np.ceil(np.sqrt(data.shape[0])))
    padding = ((0, n ** 2 - data.shape[0]), (0, padsize), (0, padsize)) + ((0, 0),) * (data.ndim - 3)
    data = np.pad(data, padding, mode='constant', constant_values=(padval, padval))

    # tile the filters into an image
    data = data.reshape((n, n) + data.shape[1:]).transpose((0, 2, 1, 3) + tuple(range(4, data.ndim + 1)))
    data = data.reshape((n * data.shape[1], n * data.shape[3]) + data.shape[4:])

    #plt.figure(figsize=image_size)
    plt.imshow(data, cmap=cmap)
    plt.show()
    plt.axis('off')