예제 #1
0
num_classes = 10
dropouts = [0.25, 0.25, 0.5]
filepath = 'weights.cifar10_e100_CNN.hdf5'

# The data, shuffled and split between train and test sets:
(x_train, y_train), (x_test, y_test) = cifar10.load_data()
print('x_train shape:', x_train.shape)
print(x_train.shape[0], 'train samples')
print(x_test.shape[0], 'test samples')

# Convert class vectors to binary class matrices.
y_train = keras.utils.to_categorical(y_train, num_classes)
y_test = keras.utils.to_categorical(y_test, num_classes)

model = cnn.define_CNN(x_train, num_classes, dropouts, 1)
print(model.summary())
model.load_weights(filepath, by_name=True)
print('Model loaded.')

# The name of the layer we want to visualize
# (see model definition in vggnet.py)
layer_name = 'fc2_out'
layer_idx = [
    idx for idx, layer in enumerate(model.layers) if layer.name == layer_name
][0]

heatmaps = []
#for path in image_paths:
for i in range(5):
    seed_img = utils.load_img(path, target_size=(32, 32))
예제 #2
0
import keras
from keras.datasets import cifar10 

kernel_size = 3 # we will use 3x3 kernels throughout
pool_size = 2 # we will use 2x2 pooling throughout
drop_prob_1 = 0.25 # dropout after pooling with probability 0.25
drop_prob_2 = 0.5 # dropout in the FC layer with probability 0.5
hidden_size = 512 # the FC layer will have 512 neurons
num_classes=10
filepath='weights.cifar10.hdf5'

# The data, shuffled and split between train and test sets:
(x_train, y_train), (x_test, y_test) = cifar10.load_data()

model = mynet.define_CNN(x_train, kernel_size, pool_size, drop_prob_1, drop_prob_2, hidden_size, num_classes, 1)
model.load_weights(filepath, by_name=True)

print('Model loaded.')

# The name of the layer we want to visualize
# (see model definition in vggnet.py)
layer_name = 'conv1'
layer_idx = [idx for idx, layer in enumerate(model.layers) if layer.name == layer_name][0]

# Visualize all filters in this layer.
filters = np.arange(get_num_filters(model.layers[layer_idx]))

# Generate input image for each filter. Here `text` field is used to overlay `filter_value` on top of the image.
vis_images = []
for idx in filters: