Untitled

mail@pastecode.io avatar
unknown
python
2 years ago
1.1 kB
1
Indexable
Never
#Prints out all available layers
for i in range(len(model.layers)):
    layer = model.layers[i]
    if 'conv' not in layer.name:
        continue    
    print(i , layer.name , layer.output.shape)



from tensorflow.keras.applications.vgg16 import preprocess_input
from tensorflow.keras.preprocessing.image import load_img
from tensorflow.keras.preprocessing.image import img_to_array
from tensorflow.keras.models import Model
from matplotlib import pyplot
from numpy import expand_dims
from matplotlib import pyplot

model1 = Model(inputs=model.inputs , outputs=model.layers[7].output)

image = load_img("../input/small-weapon-data/small weapon train/test/pistols/pistol-00322.jpg" , target_size=(256,256))

# convert the image to an array
image = img_to_array(image)
# expand dimensions so that it represents a single 'sample'
image = expand_dims(image, axis=0)

#calculating features_map
features = model1.predict(image)

fig = pyplot.figure(figsize=(20,15))
for i in range(1,features.shape[3]+1):

    pyplot.subplot(6,6,i)
    pyplot.imshow(features[0,:,:,i-1] , cmap='gray')
    
pyplot.show()