-
Notifications
You must be signed in to change notification settings - Fork 0
/
Load_Future_Vektor.py
78 lines (52 loc) · 2.28 KB
/
Load_Future_Vektor.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.callbacks import ModelCheckpoint
from keras.models import *
import numpy as np
def load_data(path):
BS=32
EPOCHS=200
train_datagen = ImageDataGenerator(rescale=1./255)
val_datagen = ImageDataGenerator(rescale = 1./255)
train_generator = train_datagen.flow_from_directory(path+'/train',
target_size=(128, 128),
batch_size = BS,
shuffle = True,class_mode='categorical')
val_generator = val_datagen.flow_from_directory(path+'/test',
target_size=(128, 128),
batch_size =BS,
shuffle =False,class_mode='categorical')
return train_generator,val_generator
def load_test(val_generator):
test_set=val_generator
test_set.reset()
testX, testY = next(test_set)
BS=32
for i in range(test_set.samples//BS):
img, label = next(test_set)
testX = np.append(testX, img, axis=0 )
testY = np.append(testY, label, axis=0)
return testX,testY
def load_train(train_generator):
train_set=train_generator
train_set.reset()
trainX, trainY = next(train_set)
BS=32
for i in range(train_set.samples//BS):
img, label = next(train_set)
trainX = np.append(trainX, img, axis=0 )
trainY = np.append(trainY, label, axis=0)
return trainX,trainY
def create_Vektor(model,data_path):
train_generator,val_generator=load_data(data_path)
testX,testY=load_test(val_generator)
trainX,trainY=load_train(train_generator)
vector_layers = ['dense_first', 'dense_two']
model_for_vector = Model(
inputs=model.input,
outputs=model.get_layer('dense_two').output#get_layer(index=90).output
)
v_X_train = model_for_vector.predict(trainX)
v_X_train = np.array(v_X_train)
v_X_test = model_for_vector.predict(testX)
v_X_test = np.array(v_X_test)
return v_X_train, v_X_test, trainY, testY