|
55 | 55 | }, |
56 | 56 | { |
57 | 57 | "cell_type": "code", |
58 | | - "execution_count": null, |
59 | | - "metadata": {}, |
60 | | - "outputs": [], |
| 58 | + "execution_count": 2, |
| 59 | + "metadata": {}, |
| 60 | + "outputs": [ |
| 61 | + { |
| 62 | + "ename": "NameError", |
| 63 | + "evalue": "name 'Zoo' is not defined", |
| 64 | + "output_type": "error", |
| 65 | + "traceback": [ |
| 66 | + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", |
| 67 | + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", |
| 68 | + "Input \u001b[0;32mIn [2]\u001b[0m, in \u001b[0;36m<cell line: 37>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 34\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mRuntimeError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mRecipe file not found: \u001b[39m\u001b[38;5;132;01m{}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;241m.\u001b[39mformat(recipe_file_path))\n\u001b[1;32m 35\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m model_file_path, recipe_file_path\n\u001b[0;32m---> 37\u001b[0m model_file_path, recipe_file_path \u001b[38;5;241m=\u001b[39m \u001b[43mdownload_model_and_recipe\u001b[49m\u001b[43m(\u001b[49m\u001b[43mroot_dir\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 39\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mLoading model \u001b[39m\u001b[38;5;132;01m{}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;241m.\u001b[39mformat(model_file_path))\n\u001b[1;32m 40\u001b[0m model \u001b[38;5;241m=\u001b[39m keras\u001b[38;5;241m.\u001b[39mmodels\u001b[38;5;241m.\u001b[39mload_model(model_file_path)\n", |
| 69 | + "Input \u001b[0;32mIn [2]\u001b[0m, in \u001b[0;36mdownload_model_and_recipe\u001b[0;34m(root_dir)\u001b[0m\n\u001b[1;32m 9\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 10\u001b[0m \u001b[38;5;124;03mDownload pretrained model and a pruning recipe\u001b[39;00m\n\u001b[1;32m 11\u001b[0m \u001b[38;5;124;03m\"\"\"\u001b[39;00m\n\u001b[1;32m 12\u001b[0m model_dir \u001b[38;5;241m=\u001b[39m os\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39mjoin(root_dir, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmnist\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m---> 13\u001b[0m zoo_model \u001b[38;5;241m=\u001b[39m \u001b[43mZoo\u001b[49m\u001b[38;5;241m.\u001b[39mload_model(\n\u001b[1;32m 14\u001b[0m domain\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcv\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 15\u001b[0m sub_domain\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mclassification\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 16\u001b[0m architecture\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmnist\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 17\u001b[0m sub_architecture\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 18\u001b[0m framework\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mkeras\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 19\u001b[0m repo\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124msparseml\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 20\u001b[0m dataset\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mmnist\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 21\u001b[0m training_scheme\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 22\u001b[0m sparse_name\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpruned\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 23\u001b[0m sparse_category\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mconservative\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m 24\u001b[0m sparse_target\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mNone\u001b[39;00m,\n\u001b[1;32m 25\u001b[0m override_parent_path\u001b[38;5;241m=\u001b[39mmodel_dir,\n\u001b[1;32m 26\u001b[0m )\n\u001b[1;32m 27\u001b[0m zoo_model\u001b[38;5;241m.\u001b[39mdownload()\n\u001b[1;32m 29\u001b[0m model_file_path \u001b[38;5;241m=\u001b[39m zoo_model\u001b[38;5;241m.\u001b[39mframework_files[\u001b[38;5;241m0\u001b[39m]\u001b[38;5;241m.\u001b[39mdownloaded_path()\n", |
| 70 | + "\u001b[0;31mNameError\u001b[0m: name 'Zoo' is not defined" |
| 71 | + ] |
| 72 | + } |
| 73 | + ], |
61 | 74 | "source": [ |
62 | 75 | "import os\n", |
63 | 76 | "from sparseml.keras.utils import keras\n", |
64 | | - "from sparsezoo.models import Zoo\n", |
| 77 | + "from sparsezoo.models import Model\n", |
65 | 78 | "\n", |
66 | 79 | "# Root directory for the notebook artifacts\n", |
67 | 80 | "root_dir = \"./notebooks/keras\"\n", |
|
71 | 84 | " Download pretrained model and a pruning recipe\n", |
72 | 85 | " \"\"\"\n", |
73 | 86 | " model_dir = os.path.join(root_dir, \"mnist\")\n", |
74 | | - " zoo_model = Zoo.load_model(\n", |
75 | | - " domain=\"cv\",\n", |
76 | | - " sub_domain=\"classification\",\n", |
77 | | - " architecture=\"mnist\",\n", |
78 | | - " sub_architecture=None,\n", |
79 | | - " framework=\"keras\",\n", |
80 | | - " repo=\"sparseml\",\n", |
81 | | - " dataset=\"mnist\",\n", |
82 | | - " training_scheme=None,\n", |
83 | | - " sparse_name=\"pruned\",\n", |
84 | | - " sparse_category=\"conservative\",\n", |
85 | | - " sparse_target=None,\n", |
86 | | - " override_parent_path=model_dir,\n", |
87 | | - " )\n", |
88 | | - " zoo_model.download()\n", |
89 | | - "\n", |
90 | | - " model_file_path = zoo_model.framework_files[0].downloaded_path()\n", |
| 87 | + " zoo_model = Model(...)\n", |
| 88 | + "\n", |
| 89 | + "\n", |
| 90 | + " model_file_path = zoo_model.training.default.get_file(\"model.h5\").path\n", |
91 | 91 | " if not os.path.exists(model_file_path) or not model_file_path.endswith(\".h5\"):\n", |
92 | 92 | " raise RuntimeError(\"Model file not found: {}\".format(model_file_path))\n", |
93 | | - " recipe_file_path = zoo_model.recipes[0].downloaded_path()\n", |
| 93 | + " recipe_file_path = zoo_model.recipes.default.path\n", |
94 | 94 | " if not os.path.exists(recipe_file_path):\n", |
95 | 95 | " raise RuntimeError(\"Recipe file not found: {}\".format(recipe_file_path))\n", |
96 | 96 | " return model_file_path, recipe_file_path\n", |
|
424 | 424 | ], |
425 | 425 | "metadata": { |
426 | 426 | "kernelspec": { |
427 | | - "display_name": "Python (keras_pruning)", |
| 427 | + "display_name": "Python 3 (ipykernel)", |
428 | 428 | "language": "python", |
429 | | - "name": "keras_pruning" |
| 429 | + "name": "python3" |
430 | 430 | }, |
431 | 431 | "language_info": { |
432 | 432 | "codemirror_mode": { |
|
438 | 438 | "name": "python", |
439 | 439 | "nbconvert_exporter": "python", |
440 | 440 | "pygments_lexer": "ipython3", |
441 | | - "version": "3.6.9" |
| 441 | + "version": "3.8.10" |
442 | 442 | } |
443 | 443 | }, |
444 | 444 | "nbformat": 4, |
|
0 commit comments