【发布时间】:2021-02-23 01:51:51
【问题描述】:
我正在使用 Colab 创建一个笔记本,用于训练机器接收字符串并以手写方式输出。我使用this Jupyter notebook 作为如何实现这样的东西的指南,因为这是我用机器学习做过的第一件事。
我已将笔记本中的 TensorFlow 降级到 1.15.2,以避免不同版本支持不同属性的问题 - 主要是因为我引用的上述笔记本是使用 TensorFlow 版本 1.X 创建的。我正在创建的笔记本使用 Python 3。
在下面的代码中,我试图绘制中风概率的高斯图。
def gauss_plot(strokes, title, figsize=(20,2)):
plt.figure(figsize=figsize)
buff = 1
epsilon = 1e-4
minx= np.min(strokes[:,0])-buff
maxx = np.max(strokes[:,0])+buff
miny = np.min(strokes[:,1])-buff
maxy = np.max(strokes[:,1])+buff
delta = abs(maxx-minx)/400. ;
x = np.arange(minx, maxx, delta)
y = np.arange(miny, maxy, delta)
X, Y = np.meshgrid(x, y)
Z = np.zeros_like(X)
for i in range(strokes.shape[0]):
gauss = mlab.bivariate_normal(X, Y, sigmax=strokes[i,2], sigmay=strokes[i,3], mux=strokes[i,0], muy=strokes[i,1], sigmaxy=0.0)
# gauss = mlab.np.compat.v1.biv_normal(X, Y, sigmax=strokes[i,2], sigmay=strokes[i,3], mux=strokes[i,0], muy=strokes[i,1], sigmaxy = 0.0 )
Z += gauss * np.power(strokes[i,3] + strokes[i,2], .4)
plt.title(title, fontsize=20)
plt.imshow(Z)
gauss_plot(strokes, "Stroke Probability", figsize=(2*model.ascii_steps,4))
我面临的问题是AttributeError: module 'matplotlib.mlab' has no attribute 'bivariate_normal'。我知道这是由于 TensorFlow 2.2.X 以及后来不支持 bivariate_normal 造成的。我遇到问题的部分是找到解决此问题的方法。我尝试通过尝试诸如“tf.compat.v1.__”之类的东西来依赖较旧的 TensorFlow 版本。我还花了几个小时研究较新的 TensorFlow 版本对应的 bivariate_normal 是什么。到目前为止,我没有运气。
我希望通过发布这篇文章,比我更熟悉机器学习的人可能能够让我知道解决这个问题的方法。
完整的错误信息是:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-33-174bc4f9cf0b> in <module>()
22 plt.imshow(Z)
23
---> 24 gauss_plot(strokes, "Stroke Probability", figsize=(2*model.ascii_steps,4))
<ipython-input-33-174bc4f9cf0b> in gauss_plot(strokes, title, figsize)
16
17 for i in range(strokes.shape[0]):
---> 18 gauss = mlab.bivariate_normal(X, Y, sigmax=strokes[i,2], sigmay=strokes[i,3], mux=strokes[i,0], muy=strokes[i,1], sigmaxy=0.0)
19 # gauss = mlab.np.compat.v1.biv_normal(X, Y, sigmax=strokes[i,2], sigmay=strokes[i,3], mux=strokes[i,0], muy=strokes[i,1], sigmaxy = 0.0 )
20 Z += gauss * np.power(strokes[i,3] + strokes[i,2], .4)
AttributeError: module 'matplotlib.mlab' has no attribute 'bivariate_normal'
【问题讨论】:
标签: tensorflow matplotlib google-colaboratory