forked from jyhong0304/SII
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_predefined_weights.py
More file actions
64 lines (52 loc) · 2.35 KB
/
Copy pathgenerate_predefined_weights.py
File metadata and controls
64 lines (52 loc) · 2.35 KB
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
63
64
import logictensornetworks as ltn
import randomly_weighted_feature_networks as rwtn
import numpy as np
import csv
import os
dirpath = os.getcwd()
# Setting
# LTN
ltn.default_layers = 6
ltn.default_smooth_factor = 1e-10
ltn.default_tnorm = "luk"
ltn.default_aggregator = "hmean"
ltn.default_positive_fact_penality = 0.
ltn.default_clauses_aggregator = "hmean"
# RWTN
rwtn.default_smooth_factor = 1e-10
rwtn.default_tnorm = "luk"
rwtn.default_aggregator = "hmean"
rwtn.default_positive_fact_penality = 0.
rwtn.default_clauses_aggregator = "hmean"
data_training_dir = dirpath + "/data/training/"
data_testing_dir = dirpath + "/data/testing/"
zero_distance_threshold = 6
number_of_features = 65
##
num_layers_object_classification = 200
num_layers_partof_detection = 400
##### Generating weights for object classification
### IN-MB input transformation
rwtn_V_object = rwtn.generate_V(num_layers=num_layers_object_classification, num_features=number_of_features - 1)
with open('./predefined_weights/rwtn_V_object.txt', 'wb') as file_rwtn_V_object:
np.save(file_rwtn_V_object, rwtn_V_object)
### Random Fourier features
rwtn_R_object = np.random.normal(size=(num_layers_object_classification, number_of_features - 1))
with open('./predefined_weights/rwtn_R_object.txt', 'wb') as file_rwtn_R_object:
np.save(file_rwtn_R_object, rwtn_R_object)
rwtn_Rb_object = np.random.uniform(low=0, high=2 * np.pi, size=(1, num_layers_object_classification))
with open('./predefined_weights/rwtn_Rb_object.txt', 'wb') as file_rwtn_Rb_object:
np.save(file_rwtn_Rb_object, rwtn_Rb_object)
##### Generating weights for part-of detection
### IN-MB input transformation
rwtn_V_pair = rwtn.generate_V(num_layers=num_layers_partof_detection, num_features=2 * (number_of_features - 1) + 2)
with open('./predefined_weights/rwtn_V_pair.txt', 'wb') as file_rwtn_V_pair:
np.save(file_rwtn_V_pair, rwtn_V_pair)
### Random Fourier features
rwtn_R_pair = np.random.normal(size=(num_layers_partof_detection, 2 * (number_of_features - 1) + 2))
with open('./predefined_weights/rwtn_R_pair.txt', 'wb') as file_rwtn_R_pair:
np.save(file_rwtn_R_pair, rwtn_R_pair)
rwtn_Rb_pair = np.random.uniform(low=0, high=2 * np.pi, size=(1, num_layers_partof_detection))
with open('./predefined_weights/rwtn_Rb_pair.txt', 'wb') as file_rwtn_Rb_pair:
np.save(file_rwtn_Rb_pair, rwtn_Rb_pair)
print("Generating weights done.")