I am pre processing a number of images(cropped,run through the network etc) which are then stored in units. From the units i am then plotting a figure with multiple subplots displaying the activations of the image at a specific convolution layer.
What i am struggling to achieve is that, given a set of more than one images which ever the number, the figures of each image, will be displayed or saved to a directory (if that makes it easier to handle in jupyter) along with each figures subplots.
Unit of a single image that turns into a unit:
[[0.0000000e+00 0.0000000e+00 0.0000000e+00 ... 3.3075356e-01
0.0000000e+00 0.0000000e+00]
[0.0000000e+00 1.4396116e-01 0.0000000e+00 ... 0.0000000e+00
0.0000000e+00 0.0000000e+00]
[0.0000000e+00 5.4249477e-01 1.9857159e-01 ... 0.0000000e+00
1.5366032e+00 1.0890217e+00]
...
[7.5161266e-01 9.6204914e-02 6.8889879e-02 ... 1.3110014e+00
5.4128194e-01 4.9922270e-01]
[7.5161266e-01 9.6204914e-02 6.8889879e-02 ... 1.3110014e+00
5.4128194e-01 4.9922270e-01]
[7.5161266e-01 9.6204914e-02 6.8889879e-02 ... 1.3110014e+00
5.4128194e-01 4.9922270e-01]]
The functions:
def getActivations(layer,stimuli):
with tf.Session(graph=graph) as sess:
#print (stimuli)
#im=stimuli
im=np.reshape(stimuli,[-1,224,224],order='F')#stimuli
im=np.expand_dims(im,axis=0)
#im=np.reshape(im,[-1,224,224],order='F')#stimuli
#plt.imshow(im,interpolation="nearest", cmap="gray")
#print (im)
#for im in stimuli:
#batch = np.array([im for i in range(1)])
x = graph.get_tensor_by_name('prefix/data:0')
#x2 = tf.reshape(x,[-1,224,224])
y=graph.get_tensor_by_name(layer)
units = sess.run(y,feed_dict={x: np.swapaxes(im,1,3)})#np.reshape(stimuli,[-1,224,224],order='F'),keep_prob:1.0})
#print (units)
plotNNFilter(units)
def plotNNFilter(units):
#for a in units:
#print ("###############################################################")
#print (units)
filters = units.shape[3]
#print ("###############################################################")
#print (filters)
plt.figure(1,figsize=(20,20))
n_columns = 6
n_rows = math.ceil(filters / n_columns) + 1
for i in range (filters):
#plt.subplot(n_rows,n_columns, i+1)
plt.subplot(n_rows,n_columns, i+1)
plt.title('Filter' + str(i))
plt.imshow(units[0,:,:,i],interpolation="nearest",cmap="gray")
I am getting this Depreciation error:
MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance. In a future version, a new instance will always be created and returned. Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance. warnings.warn(message, mplDeprecation, stacklevel=1)
I have seen another question with the same error warning:
Matplotlib: Adding an axes using the same arguments as a previous axes
Plotting on multiple figures with subplots in a single loop
But i think the answers do not apply to what i want to achieve? Due to having less than 10 reputation i can not attach an image. The image has 64 subplots, as many as the filters
Printing the len(units) so i can use the number and use it as an iteration over to do plt.figure(i,...) prints 1 for each individual unit.