我正在尝试运行以下代码
import matplotlib as plt
def plot_filters(layer, x, y):
filters = layer.get_weights()
fig = plt.figure.Figure()
for j in range(len(filters)):
ax = fig.add_subplot(y, x, j+1)
ax.matshow(filters[j][0], cmap = plt.cm.binary)
plt.xticks(np.array([]))
plt.yticks(np.array([]))
plt.tight_layout()
return plt
plot_filters(model.layers[0], 8, 4)
运行此命令时,我收到'module' object is not callable
,并且它引用了plt.tight_layout()
行。
不能弄清楚如何称呼它。它存在于matplotlib软件包中。
任何帮助将不胜感激!
谢谢
答案 0 :(得分:2)
您已将matplotlib
模块本身导入为plt
,在此应将pyplot
模块导入为plt
:
import matplotlib.pyplot as plt
import matplotlib.cm as cm
def plot_filters(layer, x, y):
filters = layer.get_weights()
fig = plt.figure()
for j in range(len(filters)):
ax = fig.add_subplot(y, x, j+1)
ax.matshow(filters[j][0], cmap = cm.binary)
plt.xticks(np.array([]))
plt.yticks(np.array([]))
plt.tight_layout()
plot_filters(model.layers[0], 8, 4)