-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainleonie.py
More file actions
105 lines (63 loc) · 3.08 KB
/
mainleonie.py
File metadata and controls
105 lines (63 loc) · 3.08 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import os
import numpy as np
from helpers.io import inputter_csv_file, inputter_videos_from_folder, outputter
from helpers.preprocessing import preprocessing, max_time, cropping, gaussian_filtering, edge_filter, min_time
from models.conv2Dclassifier import to2D
from models.Sequential_Conv3D import evaluate_sequential
# from helpers.output import output_generator
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
dir_path = os.path.dirname(os.path.realpath(__file__))
PREPROCESSING = False
# Preprocessing parameter
RESOLUTION = 1.0
if PREPROCESSING:
# Input folders
train_folder = os.path.join(dir_path, "data/train/")
test_folder = os.path.join(dir_path, "data/test/")
# Create tf records in super folder for train records outside git-repository
tf_record_dir = os.path.join(dir_path, 'tf_records')
os.makedirs(tf_record_dir, exist_ok=True)
tf_record_train = os.path.join(tf_record_dir, 'train' + '.tfrecords')
tf_record_test = os.path.join(tf_record_dir, 'test' + '.tfrecords')
x_train = inputter_videos_from_folder(train_folder)
y_train = inputter_csv_file(dir_path, 'data/train_target.csv')
x_test = inputter_videos_from_folder(test_folder)
max_time_steps = np.max((max_time(x_train), max_time(x_test)))
min_time_steps = np.min((min_time(x_train), min_time(x_test)))
x_train = preprocessing(x_train, max_time_steps, normalizing=True,
scaling=False, resolution=RESOLUTION, cut_time=True, length = min_time_steps-10, crop=0, filter='no', binary=False)
x_test = preprocessing(x_test, max_time_steps, normalizing=True,
scaling=False, resolution=RESOLUTION, cut_time=True, length= min_time_steps-10, crop=0, filter='no', binary=False)
else:
y_train = np.load('data/numpy/y_train.npy')
print("Loaded: y_train with shape {}".format(y_train.shape))
x_train = np.load('data/numpy/x_train.npy')
print("Loaded: x_train with shape {}".format(x_train.shape))
x_test = np.load('data/numpy/x_test.npy')
print("Loaded: x_test with shape {}".format(x_test.shape))
#y = evaluate_sequential(x_train,
# y_train,
# x_test)
#outputter(y)
#Idee:
a_train = np.zeros((158 * x_train.shape[1], x_train.shape[2]*x_train.shape[3]))
b = np.zeros((158 * x_train.shape[1]))
for i in range(x_train.shape[0]):
for j in range(x_train.shape[1]):
index = x_train.shape[1] * i + j
a_train[index, :] = np.ndarray.flatten(x_train[i, j, :, :, 0])
b[index] = y_train[i]
a_test = np.zeros((x_test.shape[0] * x_test.shape[1], x_test.shape[2]* x_test.shape[3]))
for i in range(x_test.shape[0]):
for j in range(x_test.shape[1]):
index = x_test.shape[1] * i + j
a_test[index, :] = np.ndarray.flatten(x_test[i, j, :, :, 0])
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import make_classification
print(x_test.shape)
print(a_test.shape)
clf = RandomForestClassifier(n_estimators=100, max_depth=2,random_state=0)
clf.fit(a_train, b)
b_test = clf.predict(a_test)
outputter(b_test)
print("output.")