Skip to content

Commit

Permalink
Tutorial/notebooks - Minor update to support notebook tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Idan-BenAmi committed Jan 22, 2024
1 parent 7638816 commit f718c1c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 24 deletions.
19 changes: 12 additions & 7 deletions tutorials/notebooks/example_keras_imagenet.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@
"source": [
"import tensorflow as tf\n",
"import keras\n",
"import model_compression_toolkit as mct"
"import model_compression_toolkit as mct\n",
"import os"
]
},
{
Expand Down Expand Up @@ -149,11 +150,12 @@
"execution_count": null,
"outputs": [],
"source": [
"!mkdir imagenet\n",
"!wget https://image-net.org/data/ILSVRC/2012/ILSVRC2012_devkit_t12.tar.gz\n",
"!mv ILSVRC2012_devkit_t12.tar.gz imagenet/\n",
"!wget https://image-net.org/data/ILSVRC/2012/ILSVRC2012_img_val.tar\n",
"!mv ILSVRC2012_img_val.tar imagenet/"
"if os.path.isdir('imagenet'):\n",
" !mkdir imagenet\n",
" !wget https://image-net.org/data/ILSVRC/2012/ILSVRC2012_devkit_t12.tar.gz\n",
" !mv ILSVRC2012_devkit_t12.tar.gz imagenet/\n",
" !wget https://image-net.org/data/ILSVRC/2012/ILSVRC2012_img_val.tar\n",
" !mv ILSVRC2012_img_val.tar imagenet/"
],
"metadata": {
"collapsed": false
Expand All @@ -176,7 +178,8 @@
"outputs": [],
"source": [
"import torchvision\n",
"ds = torchvision.datasets.ImageNet(root='./imagenet', split='val')"
"if os.path.isdir('imagenet/val'):\n",
" ds = torchvision.datasets.ImageNet(root='./imagenet', split='val')"
],
"metadata": {
"collapsed": false
Expand Down Expand Up @@ -337,11 +340,13 @@
"\n",
"# Set the following quantization configurations:\n",
"# Choose the desired QuantizationErrorMethod for the quantization parameters search.\n",
"# Enable per-channel weights quantization.\n",
"# Enable weights bias correction induced by quantization.\n",
"# Enable shift negative corrections for improving 'signed' non-linear functions quantization (such as swish, prelu, etc.) \n",
"# Set the threshold to filter outliers with z_score of 16. \n",
"q_config = mct.QuantizationConfig(activation_error_method=QuantizationErrorMethod.MSE,\n",
" weights_error_method=QuantizationErrorMethod.MSE,\n",
" weights_per_channel_threshold=True,\n",
" weights_bias_correction=True,\n",
" shift_negative_activation_correction=True,\n",
" z_threshold=16)\n",
Expand Down
17 changes: 10 additions & 7 deletions tutorials/notebooks/example_keras_mobilenet_gptq.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
"source": [
"import tensorflow as tf\n",
"import keras\n",
"import model_compression_toolkit as mct"
"import model_compression_toolkit as mct\n",
"import os"
]
},
{
Expand All @@ -81,11 +82,12 @@
"execution_count": null,
"outputs": [],
"source": [
"!mkdir imagenet\n",
"!wget https://image-net.org/data/ILSVRC/2012/ILSVRC2012_devkit_t12.tar.gz\n",
"!mv ILSVRC2012_devkit_t12.tar.gz imagenet/\n",
"!wget https://image-net.org/data/ILSVRC/2012/ILSVRC2012_img_val.tar\n",
"!mv ILSVRC2012_img_val.tar imagenet/"
"if os.path.isdir('imagenet'):\n",
" !mkdir imagenet\n",
" !wget https://image-net.org/data/ILSVRC/2012/ILSVRC2012_devkit_t12.tar.gz\n",
" !mv ILSVRC2012_devkit_t12.tar.gz imagenet/\n",
" !wget https://image-net.org/data/ILSVRC/2012/ILSVRC2012_img_val.tar\n",
" !mv ILSVRC2012_img_val.tar imagenet/"
],
"metadata": {
"collapsed": false
Expand All @@ -108,7 +110,8 @@
"outputs": [],
"source": [
"import torchvision\n",
"torchvision.datasets.ImageNet(root='./imagenet', split='val')"
"if os.path.isdir('imagenet/val'):\n",
" torchvision.datasets.ImageNet(root='./imagenet', split='val')"
],
"metadata": {
"collapsed": false
Expand Down
17 changes: 10 additions & 7 deletions tutorials/notebooks/example_keras_mobilenet_mixed_precision.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
"source": [
"import tensorflow as tf\n",
"import keras\n",
"import model_compression_toolkit as mct"
"import model_compression_toolkit as mct\n",
"import os"
]
},
{
Expand All @@ -83,11 +84,12 @@
"execution_count": null,
"outputs": [],
"source": [
"!mkdir imagenet\n",
"!wget https://image-net.org/data/ILSVRC/2012/ILSVRC2012_devkit_t12.tar.gz\n",
"!mv ILSVRC2012_devkit_t12.tar.gz imagenet/\n",
"!wget https://image-net.org/data/ILSVRC/2012/ILSVRC2012_img_val.tar\n",
"!mv ILSVRC2012_img_val.tar imagenet/"
"if os.path.isdir('imagenet'):\n",
" !mkdir imagenet\n",
" !wget https://image-net.org/data/ILSVRC/2012/ILSVRC2012_devkit_t12.tar.gz\n",
" !mv ILSVRC2012_devkit_t12.tar.gz imagenet/\n",
" !wget https://image-net.org/data/ILSVRC/2012/ILSVRC2012_img_val.tar\n",
" !mv ILSVRC2012_img_val.tar imagenet/"
],
"metadata": {
"collapsed": false
Expand All @@ -110,7 +112,8 @@
"outputs": [],
"source": [
"import torchvision\n",
"torchvision.datasets.ImageNet(root='./imagenet', split='val')"
"if os.path.isdir('imagenet/val'):\n",
" torchvision.datasets.ImageNet(root='./imagenet', split='val')"
],
"metadata": {
"collapsed": false
Expand Down
9 changes: 6 additions & 3 deletions tutorials/notebooks/example_keras_yolov8n.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,9 @@
],
"metadata": {
"kernelspec": {
"name": "local-venv",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"display_name": "local-venv"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -379,7 +379,10 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.13"
"version": "3.9.7"
},
"colab": {
"provenance": []
}
},
"nbformat": 4,
Expand Down

0 comments on commit f718c1c

Please sign in to comment.