Search code examples
pythonmachine-learningtensorflowdeep-learningdcgan

Use trained discriminator in GAN to calculate probabilities


I followed this tutorial on GAN - https://github.com/adeshpande3/Generative-Adversarial-Networks/blob/master/Generative%20Adversarial%20Networks%20Tutorial.ipynb

I want to use the trained discriminator for calculating probabilities of test images(I trained on images which represent a certain set, and want to check the probability the test image resembles that set.) I used the following code - (after reloading the model)

newP= sess.run(Dx, feed_dict={x_placeholder: dataset2})
print("prob: " + str(newP)

But It is not giving probabilities, some random floats >1. How to use the trained discrimanator for finding probabilities?


Solution

  • Use, prob = tf.nn.sigmoid(Dx) for your probabilities. Since Dx outputs a single value between 0-1, softmax for a single output will always be 1.(exp(Dx)/exp(Dx) = 1)