{"id":13526288,"url":"https://github.com/aaron-xichen/pytorch-playground","last_synced_at":"2025-05-15T08:08:01.564Z","repository":{"id":41188448,"uuid":"89674440","full_name":"aaron-xichen/pytorch-playground","owner":"aaron-xichen","description":"Base pretrained models and datasets in pytorch (MNIST, SVHN, CIFAR10, CIFAR100, STL10, AlexNet, VGG16, VGG19, ResNet, Inception, SqueezeNet)","archived":false,"fork":false,"pushed_at":"2022-11-22T04:06:41.000Z","size":47,"stargazers_count":2659,"open_issues_count":11,"forks_count":614,"subscribers_count":52,"default_branch":"master","last_synced_at":"2025-04-07T03:11:46.859Z","etag":null,"topics":["pytorch","pytorch-tutorial","pytorch-tutorials","quantization"],"latest_commit_sha":null,"homepage":"","language":"Python","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/aaron-xichen.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":"2017-04-28T06:22:30.000Z","updated_at":"2025-04-05T00:46:16.000Z","dependencies_parsed_at":"2023-01-21T18:05:18.673Z","dependency_job_id":null,"html_url":"https://github.com/aaron-xichen/pytorch-playground","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/aaron-xichen%2Fpytorch-playground","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaron-xichen%2Fpytorch-playground/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaron-xichen%2Fpytorch-playground/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaron-xichen%2Fpytorch-playground/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aaron-xichen","download_url":"https://codeload.github.com/aaron-xichen/pytorch-playground/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248870947,"owners_count":21175123,"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":["pytorch","pytorch-tutorial","pytorch-tutorials","quantization"],"created_at":"2024-08-01T06:01:27.597Z","updated_at":"2025-04-14T11:27:34.447Z","avatar_url":"https://github.com/aaron-xichen.png","language":"Python","funding_links":[],"categories":["Python","Paper implementations｜论文实现","Paper implementations","3.) Model Compression \u0026 Acceleration","Tutorials \u0026 Examples"],"sub_categories":["Other libraries｜其他库:","Other libraries:","**[Projects]**"],"readme":"This is a playground for pytorch beginners, which contains predefined models on popular dataset. Currently we support \n- mnist, svhn\n- cifar10, cifar100\n- stl10\n- alexnet\n- vgg16, vgg16_bn, vgg19, vgg19_bn\n- resnet18, resnet34, resnet50, resnet101, resnet152\n- squeezenet_v0, squeezenet_v1\n- inception_v3\n\nHere is an example for MNIST dataset. This will download the dataset and pre-trained model automatically.\n```\nimport torch\nfrom torch.autograd import Variable\nfrom utee import selector\nmodel_raw, ds_fetcher, is_imagenet = selector.select('mnist')\nds_val = ds_fetcher(batch_size=10, train=False, val=True)\nfor idx, (data, target) in enumerate(ds_val):\n    data =  Variable(torch.FloatTensor(data)).cuda()\n    output = model_raw(data)\n```\n\nAlso, if want to train the MLP model on mnist, simply run `python mnist/train.py`\n\n\n# Install\n```\npython3 setup.py develop --user\n```\n\n# ImageNet dataset\nWe provide precomputed imagenet validation dataset with 224x224x3 size. We first resize the shorter size of image to 256, then we crop 224x224 image in the center. Then we encode the cropped images to jpg string and dump to pickle. \n- `cd script`\n- Download the `val224_compressed.pkl` ([Tsinghua](http://ml.cs.tsinghua.edu.cn/~chenxi/dataset/val224_compressed.pkl) /  [Google Drive](https://drive.google.com/file/d/1U8ir2fOR4Sir3FCj9b7FQRPSVsycTfVc/view?usp=sharing))\n- `python convert.py` (needs 48G memory, thanks [@jnorwood](https://github.com/aaron-xichen/pytorch-playground/issues/18) )\n\n\n# Quantization\nWe also provide a simple demo to quantize these models to specified bit-width with several methods, including linear method, minmax method and non-linear method.\n\n`quantize --type cifar10 --quant_method linear --param_bits 8 --fwd_bits 8 --bn_bits 8 --ngpu 1`\n   \n## Top1 Accuracy\nWe evaluate the performance of popular dataset and models with linear quantized method. The bit-width of running mean and running variance in BN are 10 bits for all results. (except for 32-float)\n\n\n|Model|32-float  |12-bit  |10-bit |8-bit  |6-bit  |\n|:----|:--------:|:------:|:-----:|:-----:|:-----:|\n|[MNIST](http://ml.cs.tsinghua.edu.cn/~chenxi/pytorch-models/mnist-b07bb66b.pth)|98.42|98.43|98.44|98.44|98.32|\n|[SVHN](http://ml.cs.tsinghua.edu.cn/~chenxi/pytorch-models/svhn-f564f3d8.pth)|96.03|96.03|96.04|96.02|95.46|\n|[CIFAR10](http://ml.cs.tsinghua.edu.cn/~chenxi/pytorch-models/cifar10-d875770b.pth)|93.78|93.79|93.80|93.58|90.86|\n|[CIFAR100](http://ml.cs.tsinghua.edu.cn/~chenxi/pytorch-models/cifar100-3a55a987.pth)|74.27|74.21|74.19|73.70|66.32|\n|[STL10](http://ml.cs.tsinghua.edu.cn/~chenxi/pytorch-models/stl10-866321e9.pth)|77.59|77.65|77.70|77.59|73.40|\n|[AlexNet](https://download.pytorch.org/models/alexnet-owt-4df8aa71.pth)|55.70/78.42|55.66/78.41|55.54/78.39|54.17/77.29|18.19/36.25|\n|[VGG16](https://download.pytorch.org/models/vgg16-397923af.pth)|70.44/89.43|70.45/89.43|70.44/89.33|69.99/89.17|53.33/76.32|\n|[VGG19](https://download.pytorch.org/models/vgg19-dcbb9e9d.pth)|71.36/89.94|71.35/89.93|71.34/89.88|70.88/89.62|56.00/78.62|\n|[ResNet18](https://download.pytorch.org/models/resnet18-5c106cde.pth)|68.63/88.31|68.62/88.33|68.49/88.25|66.80/87.20|19.14/36.49|\n|[ResNet34](https://download.pytorch.org/models/resnet34-333f7ec4.pth)|72.50/90.86|72.46/90.82|72.45/90.85|71.47/90.00|32.25/55.71|\n|[ResNet50](https://download.pytorch.org/models/resnet50-19c8e357.pth)|74.98/92.17|74.94/92.12|74.91/92.09|72.54/90.44|2.43/5.36|\n|[ResNet101](https://download.pytorch.org/models/resnet101-5d3b4d8f.pth)|76.69/93.30|76.66/93.25|76.22/92.90|65.69/79.54|1.41/1.18|\n|[ResNet152](https://download.pytorch.org/models/resnet152-b121ed2d.pth)|77.55/93.59|77.51/93.62|77.40/93.54|74.95/92.46|9.29/16.75|\n|[SqueezeNetV0](https://download.pytorch.org/models/squeezenet1_0-a815701f.pth)|56.73/79.39|56.75/79.40|56.70/79.27|53.93/77.04|14.21/29.74|\n|[SqueezeNetV1](https://download.pytorch.org/models/squeezenet1_1-f364aa15.pth)|56.52/79.13|56.52/79.15|56.24/79.03|54.56/77.33|17.10/32.46|\n|[InceptionV3](https://download.pytorch.org/models/inception_v3_google-1a9a5a14.pth)|76.41/92.78|76.43/92.71|76.44/92.73|73.67/91.34|1.50/4.82|\n\n**Note: ImageNet 32-float models are directly from torchvision**\n\n\n## Selected Arguments\nHere we give an overview of selected arguments of `quantize.py`\n\n|Flag                          |Default value|Description \u0026 Options|\n|:-----------------------------|:-----------------------:|:--------------------------------|\n|type|cifar10|mnist,svhn,cifar10,cifar100,stl10,alexnet,vgg16,vgg16_bn,vgg19,vgg19_bn,resent18,resent34,resnet50,resnet101,resnet152,squeezenet_v0,squeezenet_v1,inception_v3|\n|quant_method|linear|quantization method:linear,minmax,log,tanh|\n|param_bits|8|bit-width of weights and bias|\n|fwd_bits|8|bit-width of activation|\n|bn_bits|32|bit-width of running mean and running vairance|\n|overflow_rate|0.0|overflow rate threshold for linear quantization method|\n|n_samples|20|number of samples to make statistics for activation|\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faaron-xichen%2Fpytorch-playground","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faaron-xichen%2Fpytorch-playground","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faaron-xichen%2Fpytorch-playground/lists"}