Reversing an ML model
up vote
0
down vote
favorite
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!]
python tensorflow machine-learning keras
add a comment |
up vote
0
down vote
favorite
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!]
python tensorflow machine-learning keras
3
The short and simple answer is no, you can't simply invert your classifier. Your classifier does not, as it were, know what a cat is so can't draw one. It's a (admittedly complex) one-way function from the world of images to a binarycat / not-cat
classification. The long and complex answer is long and complex and outside the possibilities offered by SO.
– High Performance Mark
Nov 19 at 15:30
I imagine that the output will probably be non-sensical most of the time. I'm also assuming that the output will be different every time, and it won't just copy one of the images that it already classified as 100% cat. It could help with determining what the model sees as cat-like features.
– Kay Tukendorf
Nov 19 at 15:31
As being said above. Try looking at Generative Adversarial Networks, or net by google called DeepDream.
– Josef Korbel
Nov 19 at 15:35
1
Oh, I could have added ... yes, you have done something wrong. You've asked a question which is too broad to be on topic here. Read again the material in the help centre which explains what questions are on topic and what are not.
– High Performance Mark
Nov 19 at 15:46
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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!]
python tensorflow machine-learning keras
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!]
python tensorflow machine-learning keras
python tensorflow machine-learning keras
asked Nov 19 at 15:19
Kay Tukendorf
65
65
3
The short and simple answer is no, you can't simply invert your classifier. Your classifier does not, as it were, know what a cat is so can't draw one. It's a (admittedly complex) one-way function from the world of images to a binarycat / not-cat
classification. The long and complex answer is long and complex and outside the possibilities offered by SO.
– High Performance Mark
Nov 19 at 15:30
I imagine that the output will probably be non-sensical most of the time. I'm also assuming that the output will be different every time, and it won't just copy one of the images that it already classified as 100% cat. It could help with determining what the model sees as cat-like features.
– Kay Tukendorf
Nov 19 at 15:31
As being said above. Try looking at Generative Adversarial Networks, or net by google called DeepDream.
– Josef Korbel
Nov 19 at 15:35
1
Oh, I could have added ... yes, you have done something wrong. You've asked a question which is too broad to be on topic here. Read again the material in the help centre which explains what questions are on topic and what are not.
– High Performance Mark
Nov 19 at 15:46
add a comment |
3
The short and simple answer is no, you can't simply invert your classifier. Your classifier does not, as it were, know what a cat is so can't draw one. It's a (admittedly complex) one-way function from the world of images to a binarycat / not-cat
classification. The long and complex answer is long and complex and outside the possibilities offered by SO.
– High Performance Mark
Nov 19 at 15:30
I imagine that the output will probably be non-sensical most of the time. I'm also assuming that the output will be different every time, and it won't just copy one of the images that it already classified as 100% cat. It could help with determining what the model sees as cat-like features.
– Kay Tukendorf
Nov 19 at 15:31
As being said above. Try looking at Generative Adversarial Networks, or net by google called DeepDream.
– Josef Korbel
Nov 19 at 15:35
1
Oh, I could have added ... yes, you have done something wrong. You've asked a question which is too broad to be on topic here. Read again the material in the help centre which explains what questions are on topic and what are not.
– High Performance Mark
Nov 19 at 15:46
3
3
The short and simple answer is no, you can't simply invert your classifier. Your classifier does not, as it were, know what a cat is so can't draw one. It's a (admittedly complex) one-way function from the world of images to a binary
cat / not-cat
classification. The long and complex answer is long and complex and outside the possibilities offered by SO.– High Performance Mark
Nov 19 at 15:30
The short and simple answer is no, you can't simply invert your classifier. Your classifier does not, as it were, know what a cat is so can't draw one. It's a (admittedly complex) one-way function from the world of images to a binary
cat / not-cat
classification. The long and complex answer is long and complex and outside the possibilities offered by SO.– High Performance Mark
Nov 19 at 15:30
I imagine that the output will probably be non-sensical most of the time. I'm also assuming that the output will be different every time, and it won't just copy one of the images that it already classified as 100% cat. It could help with determining what the model sees as cat-like features.
– Kay Tukendorf
Nov 19 at 15:31
I imagine that the output will probably be non-sensical most of the time. I'm also assuming that the output will be different every time, and it won't just copy one of the images that it already classified as 100% cat. It could help with determining what the model sees as cat-like features.
– Kay Tukendorf
Nov 19 at 15:31
As being said above. Try looking at Generative Adversarial Networks, or net by google called DeepDream.
– Josef Korbel
Nov 19 at 15:35
As being said above. Try looking at Generative Adversarial Networks, or net by google called DeepDream.
– Josef Korbel
Nov 19 at 15:35
1
1
Oh, I could have added ... yes, you have done something wrong. You've asked a question which is too broad to be on topic here. Read again the material in the help centre which explains what questions are on topic and what are not.
– High Performance Mark
Nov 19 at 15:46
Oh, I could have added ... yes, you have done something wrong. You've asked a question which is too broad to be on topic here. Read again the material in the help centre which explains what questions are on topic and what are not.
– High Performance Mark
Nov 19 at 15:46
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
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
Generator : Creates noise that is random images.
Discriminator : Gives feedback to the generator regarding the images
You can refer here.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
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
Generator : Creates noise that is random images.
Discriminator : Gives feedback to the generator regarding the images
You can refer here.
add a comment |
up vote
0
down vote
accepted
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
Generator : Creates noise that is random images.
Discriminator : Gives feedback to the generator regarding the images
You can refer here.
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
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
Generator : Creates noise that is random images.
Discriminator : Gives feedback to the generator regarding the images
You can refer here.
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
Generator : Creates noise that is random images.
Discriminator : Gives feedback to the generator regarding the images
You can refer here.
answered Nov 19 at 15:46
Shubham Panchal
17418
17418
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53377681%2freversing-an-ml-model%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
The short and simple answer is no, you can't simply invert your classifier. Your classifier does not, as it were, know what a cat is so can't draw one. It's a (admittedly complex) one-way function from the world of images to a binary
cat / not-cat
classification. The long and complex answer is long and complex and outside the possibilities offered by SO.– High Performance Mark
Nov 19 at 15:30
I imagine that the output will probably be non-sensical most of the time. I'm also assuming that the output will be different every time, and it won't just copy one of the images that it already classified as 100% cat. It could help with determining what the model sees as cat-like features.
– Kay Tukendorf
Nov 19 at 15:31
As being said above. Try looking at Generative Adversarial Networks, or net by google called DeepDream.
– Josef Korbel
Nov 19 at 15:35
1
Oh, I could have added ... yes, you have done something wrong. You've asked a question which is too broad to be on topic here. Read again the material in the help centre which explains what questions are on topic and what are not.
– High Performance Mark
Nov 19 at 15:46