<jupyter_start><jupyter_text>Build a generic CNN----(based on https://github.com/fchollet/deep-learning-with-python-notebooks)Creating a simple CNN with three convolutional layers.<jupyter_code>def build_model():
  model = models.Sequential()
  model.add(layers.Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1)))
  model.add(layers.MaxPooling2D((2, 2)))
  model.add(layers.Conv2D(64, (3, 3), activation='relu'))
  model.add(layers.MaxPooling2D((2, 2)))
  model.add(layers.Conv2D(64, (3, 3), activation='relu'))
  model.add(layers.Flatten())
  
  model.add(layers.Dense(64, activation='relu'))
  model.add(layers.Dense(10, activation='softmax'))
  model.compile(optimizer='rmsprop',
              loss='categorical_crossentropy',
              metrics=['accuracy'])
  return model

wrapper = ModelSVMWrapper(build_model())<jupyter_output><empty_output><jupyter_text>Let's display the architecture of our convnet so far:<jupyter_code>wrapper.model.summary()<jupyter_output>_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
conv2d_19 (Conv2D)           (None, 26, 26, 32)        320       
_________________________________________________________________
max_pooling2d_13 (MaxPooling (None, 13, 13, 32)        0         
_________________________________________________________________
conv2d_20 (Conv2D)           (None, 11, 11, 64)        18496     
_________________________________________________________________
max_pooling2d_14 (MaxPooling (None, 5, 5, 64)          0         
_________________________________________________________________
conv2d_21 (Conv2D)           (None, 3, 3, 64)          36928     
_________________________________________________________________
flatten_7 (Flatten)          (None, 576)               0         
_________________________________________________________________
dense_13 ([...]<jupyter_text>Prepare the data for the CNN Train model and store intermediate test results<jupyter_code>for j in range(5): 
  wrapper = ModelSVMWrapper(build_model())

  epochs = 10
  performance = {
        "with_svm@-2": [],
        "with_svm@-3": [],
        "without_svm": []
    }
  for i in range(epochs):
    print('Starting epoch: {}'.format(i + 1))
    wrapper.fit(train_images, train_labels, epochs=1, batch_size=64)
    performance["with_svm@-3"].append(wrapper.evaluate(test_images, test_labels))
    performance["without_svm"].append(
        wrapper.model.evaluate(test_images, to_categorical(test_labels))[1])

    # Try it for the different SVM
    wrapper.fit_svm(train_images, train_labels, wrapper.model.layers[-2])
    performance["with_svm@-2"].append(wrapper.evaluate(test_images, test_labels))
    
    print(performance)
  filename = 'performance{}.json'.format(j)
  print(filename)
  with  open(filename, 'w') as file:
    json.dump(performance, file)
for j in range(5): 
  filename = 'performance{}.json'.format(j)
  files.download(filename)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13771872974724564, 'fraction_numerical': 0.0356448476992871, 'mean_word_length': 4.368695652173913, 'pattern_counts': {'":': 3, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '340491', 'license': 'MIT', 'n_tokens_mistral': 971, 'n_tokens_neox': 885, 'n_words': 171, 'path': 'experiments/deep_learning_paper.ipynb', 'repo_name': 'Luttik/keras_svm', 'size': '3086'}