<jupyter_start><jupyter_text>Randomly initialized weightsThe weights should look random, and it should not be able to predict the correct class.<jupyter_code># Get weights that are not trained (i.e., randomly initialized)
model = SqueezeNet(weights=None)
W = K.eval(model.weights[0])
print(W.shape)
plt.figure(figsize=(18,12))
for idx in range(W.shape[-1]):
    plt.subplot(8,8,idx+1)
    plt.imshow(W[:,:,:,idx]); plt.colorbar()
preds = model.predict(x)
print('Predicted:', decode_predictions(preds))
# These predictions should look random (since the network is not trained)!<jupyter_output>('Predicted:', [[(u'n02110185', u'Siberian_husky', 0.0010239105), (u'n01910747', u'jellyfish', 0.0010204196), (u'n02486410', u'baboon', 0.0010175246), (u'n02643566', u'lionfish', 0.0010172399), (u'n02093754', u'Border_terrier', 0.0010149083)]])<jupyter_text>Weights pretrained over ImageNetCheck to make sure we can get the pretrained weights. The weights should have some structure, and the classification should be pretty good, since the model is already trained.<jupyter_code># Get weights that are trained over ImageNet.
model = SqueezeNet(weights='imagenet')
W = K.eval(model.weights[0])
print(W.shape)
plt.figure(figsize=(18,12))
for idx in range(W.shape[-1]):
    plt.subplot(8,8,idx+1)
    plt.imshow(W[:,:,:,idx]); plt.colorbar()
preds = model.predict(x)
print('Predicted:', decode_predictions(preds))
# Alright! These look good!<jupyter_output>('Predicted:', [[(u'n02123045', u'tabby', 0.82134342), (u'n02124075', u'Egyptian_cat', 0.12180641), (u'n02123159', u'tiger_cat', 0.05682119), (u'n02127052', u'lynx', 2.2597995e-05), (u'n02129604', u'tiger', 5.1768461e-06)]])<jupyter_text>Weights for no_topHere we will save the weights for when include_top is False. We'll do this by popping off the last few layers to get the layers we want.<jupyter_code># This is the full model layers.
model.summary()
# We don't want to use the last layer, so we'll pop() off the 1) loss, 2) pooling, 3) relu, 4) conv10, 5) dropout layers.
num_layers_to_pop = 5
for idx in range(num_layers_to_pop):
    print(model.layers.pop())
model.layers.pop()
model.summary()
model.save_weights('../weights/squeezenet_weights_tf_dim_ordering_tf_kernels_notop.h5')<jupyter_output><empty_output><jupyter_text>include_top ChecksCheck if include_top flag now works<jupyter_code>from keras.utils import get_file
model = SqueezeNet(include_top=False, weights='imagenet')
out = model.predict(x)
print(out.shape)
plt.imshow(np.squeeze(out[0,:,:,102])); plt.colorbar()
model = SqueezeNet(include_top=False, weights='imagenet', pooling='avg')
out = model.predict(x)
print(out.shape)<jupyter_output>(1, 512)
{'fraction_non_alphanumeric': 0.14960629921259844, 'fraction_numerical': 0.08136482939632546, 'mean_word_length': 6.9880239520958085, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '92465', 'license': 'MIT', 'n_tokens_mistral': 1128, 'n_tokens_neox': 983, 'n_words': 238, 'path': 'examples/.ipynb_checkpoints/example_keras_squeezenet-checkpoint.ipynb', 'repo_name': 'zr71516/squeezeNet', 'size': '2667'}