{"id":17835197,"url":"https://github.com/hsankesara/prototypical-networks","last_synced_at":"2025-03-19T15:30:28.117Z","repository":{"id":87573208,"uuid":"200040740","full_name":"Hsankesara/Prototypical-Networks","owner":"Hsankesara","description":"A novel method for few shot learning","archived":false,"fork":false,"pushed_at":"2019-11-02T10:42:01.000Z","size":939,"stargazers_count":51,"open_issues_count":3,"forks_count":12,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-02-28T19:26:58.943Z","etag":null,"topics":["computer","deep-learning","few-shot-learning","prototypical-networks"],"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/Hsankesara.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-08-01T11:48:24.000Z","updated_at":"2025-01-30T23:33:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"52df3240-1eb7-4889-9da1-5556984dfb6d","html_url":"https://github.com/Hsankesara/Prototypical-Networks","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/Hsankesara%2FPrototypical-Networks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hsankesara%2FPrototypical-Networks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hsankesara%2FPrototypical-Networks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Hsankesara%2FPrototypical-Networks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Hsankesara","download_url":"https://codeload.github.com/Hsankesara/Prototypical-Networks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243999659,"owners_count":20381399,"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":["computer","deep-learning","few-shot-learning","prototypical-networks"],"created_at":"2024-10-27T20:17:45.328Z","updated_at":"2025-03-19T15:30:28.110Z","avatar_url":"https://github.com/Hsankesara.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Prototypical Networks\n\n[![Run on FloydHub](https://static.floydhub.com/button/button-small.svg)](https://floydhub.com/run)\n\n\u003e Artificial Intelligence is the new electricity - Andrew NG\n\nThe change occurred in our life after the expeditious growth in AI and deep learning, in particular, is a solid example of this. The research is booming at unprecedented speed and lives of thousands of people have been improved. If AI is the new electricity then definitely data is the new coal. But recently we’ve seen hazardous depletion in the amount of coal in our environment. This resulted in the development of new technologies which needed a fraction of coal or even no coal at all. Similarly, there are many applications in artificial intelligence where we only have meager data or even no data at all. Hence, we need new techniques to perform well in them. Such problems resulted in the growth of a very popular field, the field of N-shot learning.\n\nTo know about it more, go to my blog at [N-Shot Learning: Learning More with Less Data](https://blog.floydhub.com/n-shot-learning/).\n\nTo check out how this works, go to my notebook at [kaggle](https://www.kaggle.com/hsankesara/prototypical-net/)\n\n\u003ctable\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003cimg src=\"img1.png\" alt=\"Basic Idea behind prototypical Network\"\u003e\u003c/td\u003e\n        \u003ctd\u003e\u003cimg src=\"img2.png\" alt=\"How prototypical Network works\"\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n\u003c/table\u003e\n\n## Dataset\n\n![Omniglot Dataset](omniglot.jpg)\n\nThe network was trained on the [Omniglot dataset](https://github.com/brendenlake/omniglot). The Omniglot data set is designed for developing more human-like learning algorithms. It contains 1623 different handwritten characters from 50 different alphabets.\n\n## How to use the Module\n\nFirst install all the necessary dependencies\n\n```bash\npip3 install -r requirements.txt\n```\n\n- Download the dataset and save it in the directory\n- To train, test and save your own model first import the PrototypicalNet module\n\n```python\nfrom prototypicalNet import PrototypicalNet, train_step, test_step, load_weights\n```\n\n```python\n# Initializing prototypical net\nprotonet = PrototypicalNet(use_gpu)\n```\n\nYou can use a pretrained model\n\n```python\n# Using Pretrained Model\nprotonet = load_weights('./protonet.pt', protonet, use_gpu)\n```\n\nOr simply train one by yourself\n\n```python\nimport torch.optim as optim\n# Set training iterations and display period\nnum_episode = 16000\nframe_size = 1000\ntrainx = trainx.permute(0, 3, 1, 2)\ntestx = testx.permute(0, 3, 1, 2)\n# Initializing prototypical net\nprotonet = PrototypicalNet(use_gpu)\noptimizer = optim.SGD(protonet.parameters(), lr = 0.01, momentum=0.99)\n# Training loop\nframe_loss = 0\nframe_acc = 0\nfor i in range(num_episode):\n    loss, acc = train_step(protonet, trainx, trainy, 5, 60, 5, optimizer)\n    frame_loss += loss.data\n    frame_acc += acc.data\n    if((i+1) % frame_size == 0):\n        print(\"Frame Number:\", ((i+1) // frame_size), 'Frame Loss: ',frame_loss.data.cpu().numpy().tolist() /\n              frame_size, 'Frame Accuracy:', (frame_acc.data.cpu().numpy(.tolist() * 100) / frame_size)\n        frame_loss = 0\n        frame_acc = 0\n```\n\nTo know more checkout [this](main.py)\n\nWant to use a customized model?\n\nNo worries, simply download the code and make suitable changes [here](prototypicalNet.py)\n\n## Project Manager\n\n**[Heet Sankesara](https://github.com/Hsankesara)**\n\n[\u003cimg src=\"http://i.imgur.com/0o48UoR.png\" width=\"35\" padding=\"10\" margin=\"10\"\u003e](https://github.com/Hsankesara/) [\u003cimg src=\"https://i.imgur.com/0IdggSZ.png\" width=\"35\" padding=\"10\" margin=\"10\"\u003e](https://www.linkedin.com/in/heet-sankesara-72383a152/) [\u003cimg src=\"http://i.imgur.com/tXSoThF.png\" width=\"35\" padding=\"10\" margin=\"10\"\u003e](https://twitter.com/heetsankesara3) [\u003cimg src=\"https://loading.io/s/icon/vzeour.svg\" width=\"35\" padding=\"10\" margin=\"10\"\u003e](https://www.kaggle.com/hsankesara)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhsankesara%2Fprototypical-networks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhsankesara%2Fprototypical-networks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhsankesara%2Fprototypical-networks/lists"}