import numpy as np
import torch
from trainVGGAE import AutoEncoderVGG
from genlabel import MyDataset
from torch.utils.data.dataloader import DataLoader
def autoencoder():
model = AutoEncoderVGG().to('cuda')
model.load_state_dict(torch.load('./VGGAE.pt'))
my_dataset = MyDataset('./samples')
data_loader = DataLoader(dataset=my_dataset, batch_size=1)
trian_x = []
label = []
for x, y in data_loader:
x = x.to(torch.float).to('cuda')
trian_x.append(np.array(model.encoder(x)[0].flatten(1).detach().to('cpu')))
label.append(y.numpy())
trian_x = np.array(trian_x).squeeze(axis=1).astype(np.float32)
label = np.array(label)
label = label.reshape(len(trian_x), 1).astype(np.float32)
train = np.concatenate((trian_x, label), axis=1)
return train