how to get value 0 or 1 in siamese neural network?
I'm trying to use siamese neural network.
Here I want to compare 2 types of images and get the results of the score,
This is the code for the test model to produce the score

in this case i use pytorch

model = Siamese()

# Load state_dict
model.load_state_dict(torch.load('/Users/tania/Desktop/TA/model/model-batch-1001.pth'))

# Create the preprocessing transformation
from torchvision import transforms
transforms = transforms.ToTensor()

# load image(s)
from PIL import Image
x1 = Image.open('table.PNG')
x2 = Image.open('table.PNG')
# Transform

x1 = transforms(x1)
x2 = transforms(x2)

x1 = torch.stack([x1])
x2 = torch.stack([x2])

model.eval()

# Get prediction
output = model(x1,x2)
print (output)


so i got the score like this, 



the score is -14.1640

basically in siamese if the image is the same then it produces a value of 1 and if different it will produce a value of 0

how do I get the value of 0 or 1 so that I know whether the image is the same or not?

please help me, i am newbie in neural network

To get an output between 0 and 1, you need to transform your values with an activation function, in order to map them to a probability. This can be done with the Sigmoid function, defined as:


It returns a probability with range (0,1) (exclusive), where values 0 &lt; y &lt; 0.5 can be interpreted as a negative label, whereas values 0.5 &lt;= y &lt; 1 can be interpreted as being positive. In PyTorch, this can be implemented:

output = model(x1,x2)
output = torch.sigmoid(output)


Hope this helps!
