-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathencode.py
More file actions
51 lines (40 loc) · 1.33 KB
/
encode.py
File metadata and controls
51 lines (40 loc) · 1.33 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
# -*- coding: utf-8 -*-
"""
Created on Sun May 31 18:08:16 2020
@author: lucas
"""
import h5py
from tensorflow.keras.models import load_model
from tensorflow import data
import tensorflow as tf
import numpy as np
from functions.generator import GetH5Generator, fuse_generators
from functions.get_encoder import get_encoder
from functions.evaluate import predict
#%%
Data_All = h5py.File("Data/All.h5")
model_name = "16_4"
batch = 13597*2
Input_gen = GetH5Generator(Data_All, preload=False, batch=batch)[0]
Input = data.Dataset.from_generator(**fuse_generators(Input_gen))
autoencoder = load_model("Autoencoder/"+model_name+"/model.h5")
encoder = get_encoder(autoencoder)
num_batches = Data_All["data"].shape[0]//batch
print(num_batches, "batches")
#%%
shape = (Data_All["data"].shape[0], encoder.output.shape[1])
File_h5 = h5py.File('Data/'+model_name+'encoded.h5', 'w')
File_mean = File_h5.create_dataset("mean", shape)
File_std = File_h5.create_dataset("std", shape)
#%%
count = 0
for x in Input:
for key in x:
x[key] = tf.dtypes.cast(x[key], tf.float32)
print("%i of %i" %(count+1, num_batches))
predictions = predict(encoder, x, 200, 42)
File_mean[count*batch:(count+1)*batch,:] = np.mean(predictions, axis=1)
File_std[count*batch:(count+1)*batch,:] = np.std(predictions, axis=1)
count+=1
#%%
File_h5.close()