Tensorflow Demo

Tensorflow is an open source library developed by Google for Deep Learning

Getting started - Mandelbrot Set


In [1]:
import tensorflow as tf
import numpy as np

import PIL.Image
from io import BytesIO
from IPython.display import Image, display

In [2]:
def DisplayFractal(a, fmt='jpeg'):
    a_cyclic = (6.28*a/20.0).reshape(list(a.shape)+[1])
    img = np.concatenate([10+20*np.cos(a_cyclic),
                          30+50*anp.sin(a_cyclic),
                          155-80*np.cos(a_cyclic)], 2)
    img[a==a.max()] = 0
    a = img
    a = np.uint8(np.clip(a, 0, 255))
    f = BytesIO()
    PIL.Image.fromarray(a).save(f, fmt)
    display(Image(data=f.getvalue()))

In [ ]:


In [3]:
sess = tf.InteractiveSession()

In [4]:
Y, X = np.mgrid[-1.3:1.3:0.005, -2:1:0.005]
Z = X+1j*Y

In [5]:
xs = tf.constant(Z.astype(np.complex64))
zs = tf.Variable(xs)
ns = tf.Variable(tf.zeros_like(xs, tf.float32))

In [ ]:


In [6]:
tf.initialize_all_variables().run()

In [7]:
zs_ = zs*zs + xs

not_diverged = tf.abs(zs_) < 4

step = tf.group(
    zs.assign(zs_),
    ns.assign_add(tf.cast(not_diverged, tf.float32))
)

In [8]:
for i in range(200): step.run()

In [9]:
DisplayFractal(ns.eval())


Look at that Mandelbrot Set!

Convolutional Neural Network


In [ ]:


In [ ]:


In [ ]: