{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.13","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":63056,"databundleVersionId":9094797,"sourceType":"competition"},{"sourceId":71549,"databundleVersionId":8561470,"sourceType":"competition"}],"dockerImageVersionId":30746,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"This notebook lists the model information of timm (PyTorch Image Models).\n\n- reference: https://github.com/huggingface/pytorch-image-models","metadata":{}},{"cell_type":"code","source":"from IPython.display import display_markdown\nimport json\nimport timm\nimport pandas as pd\n\npd.set_option('display.max_rows', 250)","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","_kg_hide-output":true,"_kg_hide-input":true,"execution":{"iopub.status.busy":"2024-08-06T03:43:54.846574Z","iopub.execute_input":"2024-08-06T03:43:54.848205Z","iopub.status.idle":"2024-08-06T03:44:02.989468Z","shell.execute_reply.started":"2024-08-06T03:43:54.848146Z","shell.execute_reply":"2024-08-06T03:44:02.986744Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"list_models = timm.list_models()\nlist_weights = timm.list_pretrained()\n\ndf = pd.DataFrame()\ndf[\"weight\"] = list_weights\ndf[\"model_name\"] = df[\"weight\"].apply(lambda x: x.split(\".\")[0])\ndf[\"model_kind\"] = df[\"model_name\"].apply(lambda x: x.split(\"_\")[0])\ndf = df[[\"model_kind\", \"model_name\", \"weight\"]]\ndf","metadata":{"_kg_hide-input":true,"_kg_hide-output":true,"execution":{"iopub.status.busy":"2024-08-06T03:44:02.992475Z","iopub.execute_input":"2024-08-06T03:44:02.993696Z","iopub.status.idle":"2024-08-06T03:44:03.080128Z","shell.execute_reply.started":"2024-08-06T03:44:02.993648Z","shell.execute_reply":"2024-08-06T03:44:03.078395Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def summary(df):\n    df_sm = df.groupby(\"model_kind\").agg({\"weight\":\"size\"}).rename(columns={\"weight\":\"# of pretrained weights\"})\n    for model_kind, gdf in df.groupby(\"model_kind\"):\n        df_sm.loc[model_kind, \"model_name\"] = str(list(gdf[\"model_name\"].unique())).replace(\"[\", \"\").replace(\"]\", \"\")\n        \n    df_sm = df_sm[[\"# of pretrained weights\", \"model_name\"]].reset_index()\n    \n    df_sm[\"model_kind\"] = df_sm[\"model_kind\"].apply(lambda x: f\"[{x}](#{x})\")\n    display_markdown(df_sm.to_markdown(), raw=True)\n\ndisplay_markdown(\"# MODELS LIST\", raw=True)\nsummary(df)\ndisplay_markdown(\"---\", raw=True)","metadata":{"_kg_hide-input":true,"execution":{"iopub.status.busy":"2024-08-06T03:44:03.08237Z","iopub.execute_input":"2024-08-06T03:44:03.082848Z","iopub.status.idle":"2024-08-06T03:44:03.82959Z","shell.execute_reply.started":"2024-08-06T03:44:03.082807Z","shell.execute_reply":"2024-08-06T03:44:03.827979Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def get_model_detail(model_name, model_weight):\n    model = timm.create_model(model_weight, pretrained=False)\n    model.eval();\n    config = timm.data.resolve_model_data_config(model)\n    transforms = timm.data.create_transform(**config, is_training=False)\n    return config, transforms\n\ndef add_model_detail_information(df_model):\n    for idx, row in df_model.iterrows():\n        config, transforms = get_model_detail(row.model_name, row.weight)\n        df_model.loc[idx, \"config\"] = str(json.dumps(config, indent=4)).replace(\"\\n\", \"<br>\")\n        df_model.loc[idx, \"transforms\"] = str(transforms).replace(\"\\n\", \"<br>\")\n    return df_model\n    \ndef model_list(df):\n    for model_kind, gdf in df.groupby(\"model_kind\"):\n        display_markdown(f\"# {model_kind}\", raw=True)\n        gdf = add_model_detail_information(gdf)\n        display_markdown(gdf.drop(columns=[\"model_kind\"]).to_markdown(), raw=True)\n\nmodel_list(df)","metadata":{"execution":{"iopub.status.busy":"2024-08-06T03:50:55.186301Z","iopub.status.idle":"2024-08-06T03:50:55.186742Z","shell.execute_reply.started":"2024-08-06T03:50:55.18653Z","shell.execute_reply":"2024-08-06T03:50:55.186546Z"},"_kg_hide-input":true,"trusted":true},"execution_count":null,"outputs":[]}]}