2017-04-01 60 views
-1

我在哪裏可以得到的代碼tensorflow教程執行Mandlebrot集? 我已經嘗試過通過粘貼出現在網站上的代碼執行,但走近「進口PIL.Image」錯誤。請幫我Mandelbrot於tensorflow設置

回答

0

聽起來像是你缺少PIL庫,它可以很容易地使用安裝:

$ pip install Pillow 

而且,你必須運行Jupyter筆記本中的代碼。

我不知道爲什麼他們在教程中使用PIL,我剛使用Matplotlib,這與Jupyter更好地整合。你可以複製/粘貼到Jupyter筆記本下面的代碼,它應該很好地工作:

%matplotlib inline 
import matplotlib 
import matplotlib.pyplot as plt 
import numpy as np 
import tensorflow as tf 

# Use NumPy to create a 2D array of complex numbers on [-2,2]x[-2,2] 
Y, X = np.mgrid[-1.3:1.3:0.005, -2:1:0.005] 
Z = X+1j*Y 

graph = tf.Graph() 
with graph.as_default(): 
    xs = tf.constant(Z.astype("complex64")) 
    zs = tf.Variable(xs) 
    ns = tf.Variable(tf.zeros_like(xs, "float32")) 

    init = tf.global_variables_initializer() 

    # Compute the new values of z: z^2 + x 
    zs_ = zs*zs + xs 

    # Have we diverged with this new value? 
    not_diverged = tf.abs(zs_) < 4 

    # Operation to update the zs and the iteration count. 
    # 
    # Note: We keep computing zs after they diverge! This 
    #  is very wasteful! There are better, if a little 
    #  less simple, ways to do this. 
    # 
    step = tf.group(
     zs.assign(zs_), 
     ns.assign_add(tf.cast(not_diverged, "float32")) 
    ) 

with tf.Session(graph=graph) as sess: 
    init.run() 
    for i in range(100): 
     step.run() 
    fractal = ns.eval() 

plt.figure(figsize=(13,8)) 
plt.imshow(fractal) 
plt.axis('off') 
plt.show()