我正在尝试运行以下代码
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)
Run Code Online (Sandbox Code Playgroud)
当运行这个时,我收到'module' object is not callable
并且它正在引用该plt.tight_layout()
行。不知道如何称呼这个。它存在于 matplotlib 包中。
任何帮助将不胜感激!
谢谢
您已将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)
Run Code Online (Sandbox Code Playgroud)