Posts

Showing posts from 2018

Image preprocessing with Numpy and Scipy

http://prancer.physics.louisville.edu/astrowiki/index.php/Image_processing_with_Python_and_SciPy key takeways: Scipy: Imread, Imsave Plt: Imshow import numpy as np import matplotlib.pyplot as plt from scipy.misc import imsave # Create the image data image_data = np.zeros(512*512, dtype=np.float32).reshape(512,512) random_data = np.random.randn(512,512) image_data = image_data + 100.*random_data print 'Size: ', image_data.size print 'Shape: ', image_data.shape scaled_image_data = image_data / 255. # Save and display the image imsave('noise.png', scaled_image_data) plt.imshow(scaled_image_data, cmap='gray') plt.show() exit()   

The difference bewteen tf.shape() and tensor.get_shape()

https://stackoverflow.com/questions/36966316/how-to-get-the-dimensions-of-a-tensor-in-tensorflow-at-graph-construction-time I see most people confused about  tf.shape(tensor)  and  tensor.get_shape()  Let's make it clear: tf.shape tf.shape  is used for dynamic shape. If your tensor's shape is  changable , use it. An example: a input is an image with changable width and height, we want resize it to half of its size, then we can write something like: new_height = tf.shape(image)[0] / 2 tensor.get_shape tensor.get_shape  is used for fixed shapes, which means the tensor's  shape can be deduced  in the graph. Conclusion:  tf.shape  can be used almost anywhere, but  t.get_shape  only for shapes can be deduced from graph. def shape ( tensor ): s = tensor . get_shape () return tuple ([ s [ i ]. value for i in range ( 0 , len ( s ))]) Example: batch_size , num_feats = shape ( logits ) ...