{"id":14970695,"url":"https://github.com/luttik/keras_svm","last_synced_at":"2025-10-26T13:31:11.089Z","repository":{"id":62573981,"uuid":"129906596","full_name":"Luttik/keras_svm","owner":"Luttik","description":null,"archived":false,"fork":false,"pushed_at":"2018-12-22T11:26:32.000Z","size":173,"stargazers_count":18,"open_issues_count":0,"forks_count":8,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-09-28T13:23:11.032Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Luttik.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-17T13:11:34.000Z","updated_at":"2023-01-28T05:02:09.000Z","dependencies_parsed_at":"2022-11-03T16:15:24.093Z","dependency_job_id":null,"html_url":"https://github.com/Luttik/keras_svm","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Luttik%2Fkeras_svm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Luttik%2Fkeras_svm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Luttik%2Fkeras_svm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Luttik%2Fkeras_svm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Luttik","download_url":"https://codeload.github.com/Luttik/keras_svm/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219862887,"owners_count":16555951,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-24T13:44:00.161Z","updated_at":"2025-10-26T13:31:10.756Z","avatar_url":"https://github.com/Luttik.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Keras SVM\n\n[![PyPI - Status](https://img.shields.io/pypi/status/keras-svm.svg)](https://pypi.org/project/keras-svm/)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/keras-svm.svg)](https://pypi.org/project/keras-svm/)\n[![PyPI - License](https://img.shields.io/pypi/l/keras-svm.svg)](https://github.com/Luttik/keras_svm/blob/master/LICENSE)\n[![PyPI](https://img.shields.io/pypi/v/keras-svm.svg)](https://pypi.org/project/keras-svm/)\n\n## Purpose\nProvides a wrapper class that effectively replaces the softmax of your Keras model with a SVM.\n\nThe SVM has no impact on the training of the Neural Network, but replacing softmax with an SVM has been shown to perform better on unseen data.\n\n## Code examples\n### Example construction\n```\n# Build a classical model\ndef build_model():\n  model = models.Sequential()\n  model.add(layers.Conv2D(32, (3, 3), activation='relu', input_shape=(28, 28, 1)))\n  model.add(layers.MaxPooling2D((2, 2)))\n  model.add(layers.Conv2D(64, (3, 3), activation='relu'))\n  model.add(layers.MaxPooling2D((2, 2)))\n  model.add(layers.Conv2D(64, (3, 3), activation='relu'))\n  model.add(layers.Flatten(name=\"intermediate_output\"))\n  model.add(layers.Dense(64, activation='relu'))\n  model.add(layers.Dense(10, activation='softmax'))\n  \n  # The extra metric is important for the evaluate function\n  model.compile(optimizer='rmsprop',\n              loss='categorical_crossentropy',\n              metrics=['accuracy'])\n  return model\n\n# Wrap it in the ModelSVMWrapper\nwrapper = ModelSVMWrapper(build_model())\n```\n\n### Training while maintaining an accuracy score\n```\naccuracy = {\n    \"with_svm\": [],\n    \"without_svm\": []\n}\n\nepochs = 10\nfor i in range(epochs):\n  print('Starting run: {}'.format(i))\n  wrapper.fit(train_images, train_labels, epochs=1, batch_size=64)\n  accuracy[\"with_svm\"].append(wrapper.evaluate(test_images, test_labels))\n  accuracy[\"without_svm\"].append(\n      wrapper.model.evaluate(test_images, to_categorical(test_labels))[1])\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluttik%2Fkeras_svm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluttik%2Fkeras_svm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluttik%2Fkeras_svm/lists"}