class Model(object): def __init__(self): self.model = CAE() model_dict = torch.load('models/CAE_model', map_location='cpu') self.model.load_state_dict(model_dict) self.model.eval def decoder(self, img, s, z): img = img / 128.0 - 1.0 img = np.transpose(img, (2, 0, 1)) img = torch.FloatTensor([img]) s = torch.FloatTensor([s]) z = torch.FloatTensor([z]) context = (img, s, z) a_tensor = self.model.decoder(context) a_numpy = a_tensor.detach().numpy()[0] return list(a_numpy)
class Model(object): def __init__(self): self.model = CAE() model_dict = torch.load('models/CAE_best_model', map_location='cpu') self.model.load_state_dict(model_dict) self.model.eval def decoder(self, z, s): if abs(z[0][0]) < 0.01: return [0.0] * 6 # z = np.asarray([z]) z = np.asarray(z) # print(s.shape) z_tensor = torch.FloatTensor(np.concatenate((z,s),axis=1)) # print(z_tensor.shape) a_tensor = self.model.decoder(z_tensor) return a_tensor.tolist() def encoder(self, a, s): x = np.concatenate((a,s),axis=1) x_tensor = torch.FloatTensor(x) z = self.model.encoder(x_tensor) return z.tolist()