-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathExample 4_random.py
62 lines (42 loc) · 1.78 KB
/
Example 4_random.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import numpy as np
import torch
from DynamicNet import DynamicCNN, convertArrayInTupleList
import random
#%% SET 1
print_var = True
tracking_input_dimension = True
parameters = {}
parameters["h"] = random.randint(80, 100)
parameters["w"] = random.randint(80, 100)
parameters["layers_cnn"] = random.randint(1, 4)
parameters["layers_ff"] = random.randint(1, 4)
parameters["layers_ff"] = 4
# parameters["h"] = 100
# parameters["w"] = 100
parameters["layers_cnn"] = 0
# parameters["layers_ff"] = 0
if(parameters["layers_cnn"] > 0):
parameters["activation_list"] = np.random.randint(0, 10, parameters["layers_cnn"] + parameters["layers_ff"] + 1)
else:
parameters["activation_list"] = np.random.randint(0, 10, parameters["layers_ff"])
parameters["kernel_list"] = []
parameters["filters_list"] = [1]
parameters["stride_list"] = []
for i in range(parameters["layers_cnn"]):
parameters["kernel_list"].append((random.randint(1, 5), random.randint(1, 5)))
parameters["filters_list"].append(random.randint(2, 64))
parameters["stride_list"].append((random.randint(1, 3), random.randint(1, 3)))
parameters["filters_list"] = convertArrayInTupleList(parameters["filters_list"])
parameters["neurons_list"] = []
for i in range(parameters["layers_ff"]):
parameters["neurons_list"].append(random.randint(2, 128))
print(parameters["neurons_list"])
model = DynamicCNN(parameters, print_var, tracking_input_dimension = tracking_input_dimension)
if(parameters["layers_cnn"] > 0):
x_test = torch.ones((1, 1, parameters["h"], parameters["w"]))
else:
x_test = torch.ones((1,parameters["neurons_list"][0]))
y_test = model(x_test)
print(model, "\n\n\n")
# for parameter in model.parameters():
# print(parameter.numel())