File size: 679 Bytes
fa128ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import torch
import numpy as np
from machinedesign.autoencoder.interface import load
from keras.models import Model
torch.use_deterministic_algorithms(True)
model = torch.load("mnist_deepconvae/model.th")
model_keras = load("/home/mehdi/work/code/out_of_class/ae/mnist")
print(model_keras.layers[8])

m = Model(model_keras.inputs, model_keras.layers[8].output)
X = torch.rand(1,1,28,28)
with torch.no_grad():
    # X1 = model.sparsify(model.encode(X))
    X1 = model(X)
X2 = model_keras.predict(X)
X2 = torch.from_numpy(X2)
print(torch.abs(X1-X2).sum())
# for i in range(128):
    # print(i, torch.abs(X1[0,i]-X2[0,i]).sum())
    # print(X1[0,i, 0, :])
    # print(X2[0,i,0, :])