Skip to content

Commit f0b1fc5

Browse files
committed
Start adding demo
1 parent a9bc279 commit f0b1fc5

6 files changed

Lines changed: 114 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ solve*.sh
2727
*.egg-info
2828
ddpm_chk.txt
2929
ddpm_mgd.txt
30+
.ipynb_checkpoints/

examples/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.pth

examples/0_demo.ipynb

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 6,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"ename": "ModuleNotFoundError",
10+
"evalue": "No module named 'torchvision'",
11+
"output_type": "error",
12+
"traceback": [
13+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
14+
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
15+
"Input \u001b[0;32mIn [6]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m# This demo code is inspired by https://github.com/facebookresearch/ToMe/blob/main/examples/0_validation_timm.ipynb.\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mtorchvision\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m transforms\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mtorchvision\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mtransforms\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mfunctional\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m InterpolationMode\n\u001b[1;32m 4\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mPIL\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m Image\n",
16+
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'torchvision'"
17+
]
18+
}
19+
],
20+
"source": [
21+
"# This demo code is inspired by https://github.com/facebookresearch/ToMe/blob/main/examples/0_validation_timm.ipynb.\n",
22+
"from torchvision import transforms\n",
23+
"from torchvision.transforms.functional import InterpolationMode\n",
24+
"from PIL import Image"
25+
]
26+
},
27+
{
28+
"cell_type": "code",
29+
"execution_count": null,
30+
"metadata": {},
31+
"outputs": [],
32+
"source": [
33+
"!wget -O mobilenetv2_100_ra-b33bc2c4.pth --no-check-certificate -r 'https://drive.google.com/uc?export=download&id=1r_ToZhZP7cz6DZh4f3r1VWf0fpdGL0XX'"
34+
]
35+
},
36+
{
37+
"cell_type": "code",
38+
"execution_count": 3,
39+
"metadata": {},
40+
"outputs": [
41+
{
42+
"ename": "ModuleNotFoundError",
43+
"evalue": "No module named 'layer_merge'",
44+
"output_type": "error",
45+
"traceback": [
46+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
47+
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
48+
"Input \u001b[0;32mIn [3]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m# MobileNetV2-1.0\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mlayer_merge\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mmodels\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mmobilenetv2\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m MobileNetV2\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mlayer_merge\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mmodels\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mmobilenetv2_merged_layer\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m make_depth_layer_mobilenet_v2\n\u001b[1;32m 6\u001b[0m pretrained_model \u001b[38;5;241m=\u001b[39m MobileNetV2()\n",
49+
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'layer_merge'"
50+
]
51+
}
52+
],
53+
"source": [
54+
"# MobileNetV2-1.0\n",
55+
"from layer_merge.models.mobilenetv2 import MobileNetV2\n",
56+
"from layer_merge.models.mobilenetv2_merged_layer import make_depth_layer_mobilenet_v2\n",
57+
"\n",
58+
"\n",
59+
"pretrained_model = MobileNetV2()"
60+
]
61+
},
62+
{
63+
"cell_type": "code",
64+
"execution_count": null,
65+
"metadata": {},
66+
"outputs": [],
67+
"source": [
68+
"input_size = 224\n",
69+
"transform = transforms.Compose([\n",
70+
" transforms.Resize(256),\n",
71+
" transforms.CenterCrop(input_size),\n",
72+
" transforms.ToTensor(),\n",
73+
" transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])\n",
74+
"])\n",
75+
"img = Image.open(\"images/husky.png\")\n",
76+
"img_tensor = transform(img)[None, ...]\n",
77+
"\n",
78+
"img # Note: image generated with stable diffusion"
79+
]
80+
},
81+
{
82+
"cell_type": "code",
83+
"execution_count": null,
84+
"metadata": {},
85+
"outputs": [],
86+
"source": []
87+
}
88+
],
89+
"metadata": {
90+
"kernelspec": {
91+
"display_name": "Python 3 (ipykernel)",
92+
"language": "python",
93+
"name": "python3"
94+
},
95+
"language_info": {
96+
"codemirror_mode": {
97+
"name": "ipython",
98+
"version": 3
99+
},
100+
"file_extension": ".py",
101+
"mimetype": "text/x-python",
102+
"name": "python",
103+
"nbconvert_exporter": "python",
104+
"pygments_lexer": "ipython3",
105+
"version": "3.9.5"
106+
}
107+
},
108+
"nbformat": 4,
109+
"nbformat_minor": 2
110+
}

examples/ckpt/.keep

Whitespace-only changes.

examples/images/husky.png

445 KB
Loading

requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,5 @@ torchvision==0.13.1+cu113
1515
lmdb==1.4.1
1616
tensorboard==2.11.2
1717
accelerate==0.20.3
18+
jupyter==1.0.0
19+
notebook==6.4.12

0 commit comments

Comments
 (0)