Skip to content

Commit b0b2920

Browse files
committed
clean repository
1 parent 10f2ce6 commit b0b2920

14 files changed

+428
-252
lines changed

code/best_models.zip

-8.22 KB
Binary file not shown.

code/create_GCN_dataset.py

Lines changed: 0 additions & 61 deletions
This file was deleted.

code/data_generator.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import random
2+
import nni
3+
import numpy as np
4+
5+
import io
6+
import graphviz
7+
import matplotlib.pyplot as plt
8+
from PIL import Image
9+
10+
import json
11+
import os
12+
13+
from tqdm.notebook import tqdm
14+
15+
16+
DARTS_OPS = [
17+
# 'none',
18+
"max_pool_3x3",
19+
"avg_pool_3x3",
20+
"skip_connect",
21+
"sep_conv_3x3",
22+
"sep_conv_5x5",
23+
"dil_conv_3x3",
24+
"dil_conv_5x5",
25+
]
26+
27+
28+
def generate_cells(num_nodes, name='normal', operations=DARTS_OPS):
29+
cells = dict()
30+
for i in range(num_nodes - 1):
31+
cur_indexes = list(range(0, i + 2))
32+
random_op_0, random_op_1 = random.choices(operations, k=2)
33+
34+
random_index_0, random_index_1 = random.sample(cur_indexes, k=2)
35+
36+
op_str_0 = f'{name}/op_{i + 2}_0'
37+
op_str_1 = f'{name}/op_{i + 2}_1'
38+
input_str_0 = f'{name}/input_{i + 2}_0'
39+
input_str_1 = f'{name}/input_{i + 2}_1'
40+
41+
cells[op_str_0] = random_op_0
42+
cells[input_str_0] = [random_index_0]
43+
cells[op_str_1] = random_op_1
44+
cells[input_str_1] = [random_index_1]
45+
46+
return cells
47+
48+
def generate_arch_dicts(N_MODELS):
49+
arch_dicts = []
50+
for _ in tqdm(range(N_MODELS)):
51+
normal_cell = generate_cells(5, name='normal')
52+
reduction_cell = generate_cells(5, name='reduce')
53+
arch_dict = {**normal_cell, **reduction_cell}
54+
arch_dicts.append(arch_dict)
55+
return arch_dicts
56+
57+
if __name__ == "__main__":
58+
N_MODELS = 3
59+
arch_dicts = generate_arch_dicts(N_MODELS)
60+
print(arch_dicts)

code/dependecies.zip

-5.63 KB
Binary file not shown.

code/finding-best-models-gcn.ipynb

Lines changed: 69 additions & 68 deletions
Large diffs are not rendered by default.

code/gcn-training.ipynb

Lines changed: 116 additions & 123 deletions
Large diffs are not rendered by default.

code/greedy_finding_best_models.ipynb

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [
8+
{
9+
"name": "stdout",
10+
"output_type": "stream",
11+
"text": [
12+
"\u001b[1;31merror\u001b[0m: \u001b[1mexternally-managed-environment\u001b[0m\n",
13+
"\n",
14+
"\u001b[31m×\u001b[0m This environment is externally managed\n",
15+
"\u001b[31m╰─>\u001b[0m To install Python packages system-wide, try apt install\n",
16+
"\u001b[31m \u001b[0m python3-xyz, where xyz is the package you are trying to\n",
17+
"\u001b[31m \u001b[0m install.\n",
18+
"\u001b[31m \u001b[0m \n",
19+
"\u001b[31m \u001b[0m If you wish to install a non-Debian-packaged Python package,\n",
20+
"\u001b[31m \u001b[0m create a virtual environment using python3 -m venv path/to/venv.\n",
21+
"\u001b[31m \u001b[0m Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make\n",
22+
"\u001b[31m \u001b[0m sure you have python3-full installed.\n",
23+
"\u001b[31m \u001b[0m \n",
24+
"\u001b[31m \u001b[0m If you wish to install a non-Debian packaged Python application,\n",
25+
"\u001b[31m \u001b[0m it may be easiest to use pipx install xyz, which will manage a\n",
26+
"\u001b[31m \u001b[0m virtual environment for you. Make sure you have pipx installed.\n",
27+
"\u001b[31m \u001b[0m \n",
28+
"\u001b[31m \u001b[0m See /usr/share/doc/python3.12/README.venv for more information.\n",
29+
"\n",
30+
"\u001b[1;35mnote\u001b[0m: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.\n",
31+
"\u001b[1;36mhint\u001b[0m: See PEP 668 for the detailed specification.\n"
32+
]
33+
}
34+
],
35+
"source": [
36+
"!pip install torch_geometric --quiet"
37+
]
38+
},
39+
{
40+
"cell_type": "code",
41+
"execution_count": 2,
42+
"metadata": {},
43+
"outputs": [],
44+
"source": [
45+
"import numpy as np\n",
46+
"import torch\n",
47+
"import torch.nn.functional as F\n",
48+
"import os\n",
49+
"import json\n",
50+
"from torch_geometric.utils import dense_to_sparse\n",
51+
"import matplotlib.pyplot as plt\n",
52+
"from sklearn.decomposition import PCA\n",
53+
"from sklearn.cluster import OPTICS, DBSCAN\n",
54+
"from tqdm.notebook import tqdm\n",
55+
"from torch.utils.data import Dataset\n",
56+
"\n",
57+
"# Custom imports\n",
58+
"import sys\n",
59+
"sys.path.insert(1, \"/kaggle/input/second-dataset/dependecies\")\n",
60+
"\n",
61+
"import GCN\n",
62+
"from Graph import Graph\n",
63+
"\n",
64+
"device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n",
65+
"TEST = False"
66+
]
67+
},
68+
{
69+
"cell_type": "code",
70+
"execution_count": 3,
71+
"metadata": {},
72+
"outputs": [],
73+
"source": [
74+
"model_diversity_path = \"weights/model_diversity_weights.pth\"\n",
75+
"model_accuracy_path = \"weights/model_accuracy_weights.pth\""
76+
]
77+
},
78+
{
79+
"cell_type": "code",
80+
"execution_count": 4,
81+
"metadata": {},
82+
"outputs": [
83+
{
84+
"data": {
85+
"text/plain": [
86+
"GCN(\n",
87+
" (gc1): GCNConv(8, 64)\n",
88+
" (gc2): GCNConv(64, 256)\n",
89+
" (gc3): GCNConv(256, 512)\n",
90+
" (gc4): GCNConv(512, 64)\n",
91+
" (residual_proj): Linear(in_features=8, out_features=64, bias=True)\n",
92+
" (layer_norm): LayerNorm((64,), eps=1e-05, elementwise_affine=True)\n",
93+
" (dropout): Dropout(p=0, inplace=False)\n",
94+
" (fc1): Linear(in_features=64, out_features=64, bias=True)\n",
95+
" (fc_norm): LayerNorm((64,), eps=1e-05, elementwise_affine=True)\n",
96+
" (fc2): Linear(in_features=64, out_features=16, bias=True)\n",
97+
")"
98+
]
99+
},
100+
"execution_count": 4,
101+
"metadata": {},
102+
"output_type": "execute_result"
103+
}
104+
],
105+
"source": [
106+
"input_dim = 8\n",
107+
"output_dim = 16\n",
108+
"dropout=0\n",
109+
"\n",
110+
"model_diverisity = GCN.GCN(input_dim, output_dim, dropout).to(device)\n",
111+
"state_dict = torch.load(model_diversity_path, map_location=device, weights_only=True)\n",
112+
"model_diverisity.load_state_dict(state_dict)\n",
113+
"model_diverisity.eval()"
114+
]
115+
},
116+
{
117+
"cell_type": "code",
118+
"execution_count": 5,
119+
"metadata": {},
120+
"outputs": [
121+
{
122+
"data": {
123+
"text/plain": [
124+
"GCN(\n",
125+
" (gc1): GCNConv(8, 64)\n",
126+
" (gc2): GCNConv(64, 256)\n",
127+
" (gc3): GCNConv(256, 512)\n",
128+
" (gc4): GCNConv(512, 64)\n",
129+
" (residual_proj): Linear(in_features=8, out_features=64, bias=True)\n",
130+
" (layer_norm): LayerNorm((64,), eps=1e-05, elementwise_affine=True)\n",
131+
" (dropout): Dropout(p=0, inplace=False)\n",
132+
" (fc1): Linear(in_features=64, out_features=64, bias=True)\n",
133+
" (fc_norm): LayerNorm((64,), eps=1e-05, elementwise_affine=True)\n",
134+
" (fc2): Linear(in_features=64, out_features=1, bias=True)\n",
135+
")"
136+
]
137+
},
138+
"execution_count": 5,
139+
"metadata": {},
140+
"output_type": "execute_result"
141+
}
142+
],
143+
"source": [
144+
"input_dim = 8\n",
145+
"output_dim = 1\n",
146+
"dropout = 0\n",
147+
"\n",
148+
"model_accuracy = GCN.GCN(input_dim, output_dim, dropout).to(device)\n",
149+
"state_dict = torch.load(model_accuracy_path, map_location=device, weights_only=True)\n",
150+
"model_accuracy.load_state_dict(state_dict)\n",
151+
"model_accuracy.eval()"
152+
]
153+
},
154+
{
155+
"cell_type": "code",
156+
"execution_count": null,
157+
"metadata": {},
158+
"outputs": [],
159+
"source": []
160+
}
161+
],
162+
"metadata": {
163+
"kernelspec": {
164+
"display_name": "Python 3",
165+
"language": "python",
166+
"name": "python3"
167+
},
168+
"language_info": {
169+
"codemirror_mode": {
170+
"name": "ipython",
171+
"version": 3
172+
},
173+
"file_extension": ".py",
174+
"mimetype": "text/x-python",
175+
"name": "python",
176+
"nbconvert_exporter": "python",
177+
"pygments_lexer": "ipython3",
178+
"version": "3.12.3"
179+
}
180+
},
181+
"nbformat": 4,
182+
"nbformat_minor": 2
183+
}

code/model_accuracy_weights.pth

-736 KB
Binary file not shown.

code/model_diversity_weights.pth

-739 KB
Binary file not shown.

code/weights.zip

-1.32 MB
Binary file not shown.
736 KB
Binary file not shown.
740 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)