Kay Tukendorf
Kay Tukendorf

Reputation: 57

Reversing an ML model

I am currently teaching myself the basics of machine learning by creating a simple image classifier using Keras (with a Tensorflow backend). The model classifies a (greyscaled) image as either a cat or not a cat.

My model is relatively good at this task, so I now want to see if it can generate images that it would classify as a cat.

I have attempted to start this in a simple way, by creating a random array of the same shape as the images, with random numbers in each index:

    from random import randint

    json_file = open('model.json', 'r')
    loaded_model_json = json_file.read()
    json_file.close()
    model = model_from_json(loaded_model_json)
    model.load_weights("model_weights.h5")

    confidence = 0.0
    thresholdConfidence = 0.6

    while confidence < thresholdConfidence:
        img_array = np.array([[[randint(0, 255) for z in range(1)] for y in range(64)] for x in range(64)])
        img_array = img_array.reshape((1,) + img_array.shape)
        confidence = model.predict(img_array)

This method is obviously not good at all, since it just creates random things and could potentially run eternally. Could the model somehow run in reverse by telling it that an array is 100% cat, and having it predict what the array representation of the image is?

Thank you for reading.

[This is my first post on StackOverflow, so please let me know if I've done something wrong!]

Upvotes: 1

Views: 1050

Answers (1)

user9477964
user9477964

Reputation:

If you wish to generate a special type of image, you can use Generative Adversary Networks. This are made into two parts which need to be trained separately. The two parts are

  1. Generator : Creates noise that is random images.
  2. Discriminator : Gives feedback to the generator regarding the images

You can refer here.

Upvotes: 1

Related Questions