Reputation: 3071
im trying to run the following code
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)
when running this I am receiving 'module' object is not callable
and it is referencing the plt.tight_layout()
line.
Cant figure out how to call this. It is present in the matplotlib package.
Any help will be appreciated!
Thanks
Upvotes: 1
Views: 1833
Reputation: 1
try to write it like this
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([]))
fig.tight_layout()
plot_filters(model.layers[0], 8, 4)
Upvotes: 0
Reputation: 25362
You have imported the matplotlib
module itself as plt
, where you should be importing the pyplot
module as plt
instead:
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)
Upvotes: 5