Skip to content

Instantly share code, notes, and snippets.

@SubhadityaMukherjee
Created January 21, 2020 16:20
Show Gist options
  • Save SubhadityaMukherjee/863d9c18c02f91cc03fad866da481f53 to your computer and use it in GitHub Desktop.
Save SubhadityaMukherjee/863d9c18c02f91cc03fad866da481f53 to your computer and use it in GitHub Desktop.
downloadres

url = 'https://nicolekessler.files.wordpress.com/2013/04/hellish_demons.jpg?w=1024'

Download

  • We first download the image
  • Resize it for faster computation

def download(url, max_dim=None): name = "demons.jpg" image_path = tf.keras.utils.get_file(name, origin=url) img = PIL.Image.open(image_path) if max_dim: img.thumbnail((max_dim, max_dim)) return np.array(img)

Deprocess

  • This is a process called normalization
  • tf.cast is used to convert the tensor into a 8 bit integer value representation

def deprocess(img): img = 255 * (img + 1.0) / 2.0 return tf.cast(img, tf.uint8)

Show

  • just a wrapper to convert the tensor into an array and display

def show(img): display.display(PIL.Image.fromarray(np.array(img)))

original_img = download(url, max_dim=500) show(original_img)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment