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!]
python tensorflow machine-learning keras
add a comment |
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 '18 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 '18 at 15:31
As being said above. Try looking at Generative Adversarial Networks, or net by google called DeepDream.
– Josef Korbel
Nov 19 '18 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 '18 at 15:46
add a comment |
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 '18 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 '18 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 '18 at 15:31
As being said above. Try looking at Generative Adversarial Networks, or net by google called DeepDream.
– Josef Korbel
Nov 19 '18 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 '18 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 '18 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 '18 at 15:31
As being said above. Try looking at Generative Adversarial Networks, or net by google called DeepDream.
– Josef Korbel
Nov 19 '18 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 '18 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 '18 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 '18 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 '18 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 '18 at 15:31
As being said above. Try looking at Generative Adversarial Networks, or net by google called DeepDream.
– Josef Korbel
Nov 19 '18 at 15:35
As being said above. Try looking at Generative Adversarial Networks, or net by google called DeepDream.
– Josef Korbel
Nov 19 '18 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 '18 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 '18 at 15:46
add a comment |
1 Answer
1
active
oldest
votes
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 |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 |
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 |
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 '18 at 15:46


Shubham Panchal
459110
459110
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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 '18 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 '18 at 15:31
As being said above. Try looking at Generative Adversarial Networks, or net by google called DeepDream.
– Josef Korbel
Nov 19 '18 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 '18 at 15:46