CoreML2 keeps telling me everything is the same thing
I am trying to start small and have trained my model with 2 items. It recognises both just fine but when I show it something other than the 2 items it knows, it keeps telling me that is is always the same item. For example, I have an apple and banana. If I show it the apple, it correctly gives me apple, if I show it a banana it correctly returns banana. But if I show it a dog, it tells me it is an apple. If I show it a helicopter it tells me it is an apple. I even tried an if statement to say that if it isn't an apple or a banana then just return that it can't be recognised, but that never comes because everything besides the banana is always an apple?!
EDIT
My question was down voted perhaps because of a misunderstanding. I am not asking why it doesn't recognise a dog when I have only trained an apple and banana, I am asking why it doesn't tell me that the image is unrecognised when I show it a dog instead of telling me it's an apple. Obviously if I have only trained it with 2 items it is only going to recognise 2 items.
Here is the code that returns the classifications
func processClassifications(for request: VNRequest, error: Error?) {
DispatchQueue.main.async {
guard let results = request.results else {
self.classificationLabel.text = "Unable to classify image"
return
}
let classifications = results as! [VNClassificationObservation]
if classifications.isEmpty {
self.classificationLabel.text = "Nothing recognized"
} else {
//Display top classifications ranked by confidence in the UI
let topClassifications = classifications.prefix(1)
let descriptions = topClassifications.map { classification in
return String(format: " (%.2f) %@", classification.confidence, classification.identifier)
}
self.classificationLabel.text = descriptions.joined(separator: "n")
}
}
}
swift coreml
add a comment |
I am trying to start small and have trained my model with 2 items. It recognises both just fine but when I show it something other than the 2 items it knows, it keeps telling me that is is always the same item. For example, I have an apple and banana. If I show it the apple, it correctly gives me apple, if I show it a banana it correctly returns banana. But if I show it a dog, it tells me it is an apple. If I show it a helicopter it tells me it is an apple. I even tried an if statement to say that if it isn't an apple or a banana then just return that it can't be recognised, but that never comes because everything besides the banana is always an apple?!
EDIT
My question was down voted perhaps because of a misunderstanding. I am not asking why it doesn't recognise a dog when I have only trained an apple and banana, I am asking why it doesn't tell me that the image is unrecognised when I show it a dog instead of telling me it's an apple. Obviously if I have only trained it with 2 items it is only going to recognise 2 items.
Here is the code that returns the classifications
func processClassifications(for request: VNRequest, error: Error?) {
DispatchQueue.main.async {
guard let results = request.results else {
self.classificationLabel.text = "Unable to classify image"
return
}
let classifications = results as! [VNClassificationObservation]
if classifications.isEmpty {
self.classificationLabel.text = "Nothing recognized"
} else {
//Display top classifications ranked by confidence in the UI
let topClassifications = classifications.prefix(1)
let descriptions = topClassifications.map { classification in
return String(format: " (%.2f) %@", classification.confidence, classification.identifier)
}
self.classificationLabel.text = descriptions.joined(separator: "n")
}
}
}
swift coreml
1
create one more item called Unknowned
– canister_exister
Nov 12 at 19:52
That's worth a shot.
– user8463989
Nov 12 at 19:54
add a comment |
I am trying to start small and have trained my model with 2 items. It recognises both just fine but when I show it something other than the 2 items it knows, it keeps telling me that is is always the same item. For example, I have an apple and banana. If I show it the apple, it correctly gives me apple, if I show it a banana it correctly returns banana. But if I show it a dog, it tells me it is an apple. If I show it a helicopter it tells me it is an apple. I even tried an if statement to say that if it isn't an apple or a banana then just return that it can't be recognised, but that never comes because everything besides the banana is always an apple?!
EDIT
My question was down voted perhaps because of a misunderstanding. I am not asking why it doesn't recognise a dog when I have only trained an apple and banana, I am asking why it doesn't tell me that the image is unrecognised when I show it a dog instead of telling me it's an apple. Obviously if I have only trained it with 2 items it is only going to recognise 2 items.
Here is the code that returns the classifications
func processClassifications(for request: VNRequest, error: Error?) {
DispatchQueue.main.async {
guard let results = request.results else {
self.classificationLabel.text = "Unable to classify image"
return
}
let classifications = results as! [VNClassificationObservation]
if classifications.isEmpty {
self.classificationLabel.text = "Nothing recognized"
} else {
//Display top classifications ranked by confidence in the UI
let topClassifications = classifications.prefix(1)
let descriptions = topClassifications.map { classification in
return String(format: " (%.2f) %@", classification.confidence, classification.identifier)
}
self.classificationLabel.text = descriptions.joined(separator: "n")
}
}
}
swift coreml
I am trying to start small and have trained my model with 2 items. It recognises both just fine but when I show it something other than the 2 items it knows, it keeps telling me that is is always the same item. For example, I have an apple and banana. If I show it the apple, it correctly gives me apple, if I show it a banana it correctly returns banana. But if I show it a dog, it tells me it is an apple. If I show it a helicopter it tells me it is an apple. I even tried an if statement to say that if it isn't an apple or a banana then just return that it can't be recognised, but that never comes because everything besides the banana is always an apple?!
EDIT
My question was down voted perhaps because of a misunderstanding. I am not asking why it doesn't recognise a dog when I have only trained an apple and banana, I am asking why it doesn't tell me that the image is unrecognised when I show it a dog instead of telling me it's an apple. Obviously if I have only trained it with 2 items it is only going to recognise 2 items.
Here is the code that returns the classifications
func processClassifications(for request: VNRequest, error: Error?) {
DispatchQueue.main.async {
guard let results = request.results else {
self.classificationLabel.text = "Unable to classify image"
return
}
let classifications = results as! [VNClassificationObservation]
if classifications.isEmpty {
self.classificationLabel.text = "Nothing recognized"
} else {
//Display top classifications ranked by confidence in the UI
let topClassifications = classifications.prefix(1)
let descriptions = topClassifications.map { classification in
return String(format: " (%.2f) %@", classification.confidence, classification.identifier)
}
self.classificationLabel.text = descriptions.joined(separator: "n")
}
}
}
swift coreml
swift coreml
edited Nov 12 at 20:04
asked Nov 12 at 19:33
user8463989
11810
11810
1
create one more item called Unknowned
– canister_exister
Nov 12 at 19:52
That's worth a shot.
– user8463989
Nov 12 at 19:54
add a comment |
1
create one more item called Unknowned
– canister_exister
Nov 12 at 19:52
That's worth a shot.
– user8463989
Nov 12 at 19:54
1
1
create one more item called Unknowned
– canister_exister
Nov 12 at 19:52
create one more item called Unknowned
– canister_exister
Nov 12 at 19:52
That's worth a shot.
– user8463989
Nov 12 at 19:54
That's worth a shot.
– user8463989
Nov 12 at 19:54
add a comment |
2 Answers
2
active
oldest
votes
If you have model trained with 2 items only (in your case Apple and Banana) you can't expect that your ML model recognize something else than these 2 items.
Code you wrote always return item which will have the biggest confidence.
If you want to return item just if topClassification with your testing image match at least for example 75% replace this
if classifications.isEmpty {
self.classificationLabel.text = "Nothing recognized"
} else {
//Display top classifications ranked by confidence in the UI
let topClassifications = classifications.prefix(1)
let descriptions = topClassifications.map { classification in
return String(format: " (%.2f) %@", classification.confidence, classification.identifier)
}
self.classificationLabel.text = descriptions.joined(separator: "n")
}
with
guard let topResult = classifications.first else { return }
if topResult.confidence > 0.75 {
print(topResult.identifier)
} else {
print("Match is less than 75%")
}
I would have thought though if you show it something that looks nothing like those 2 items it would not recognise it instead of telling you it is always one of the two things? I would rather have a not recognised message than everything being an apple
– user8463989
Nov 12 at 19:48
I am not expecitng it to give me the correct names for something I haven't trained, but I am not expecting it to tell me everything is an apple but rather that it doesn't recognise something that isn't an apple or a banana
– user8463989
Nov 12 at 19:52
@user8463989 try edited answer
– Robert Dresler
Nov 12 at 20:11
thanks for that. It would have been perfect if the unknown images would score that low. I checked the scores and for a picture of a waterfall it seems to know with 100% certainty that it is an apple. So, that code of yours never fires.
– user8463989
Nov 13 at 8:05
@user8463989 If you print topResult.confidence right above if statement what is printed?
– Robert Dresler
Nov 13 at 8:36
|
show 3 more comments
In a model that is a classifier, you always get just as many VNClassificationObservation
objects as there are classes. No more, no less. The array is only empty if there was a problem running the model.
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%2f53268919%2fcoreml2-keeps-telling-me-everything-is-the-same-thing%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you have model trained with 2 items only (in your case Apple and Banana) you can't expect that your ML model recognize something else than these 2 items.
Code you wrote always return item which will have the biggest confidence.
If you want to return item just if topClassification with your testing image match at least for example 75% replace this
if classifications.isEmpty {
self.classificationLabel.text = "Nothing recognized"
} else {
//Display top classifications ranked by confidence in the UI
let topClassifications = classifications.prefix(1)
let descriptions = topClassifications.map { classification in
return String(format: " (%.2f) %@", classification.confidence, classification.identifier)
}
self.classificationLabel.text = descriptions.joined(separator: "n")
}
with
guard let topResult = classifications.first else { return }
if topResult.confidence > 0.75 {
print(topResult.identifier)
} else {
print("Match is less than 75%")
}
I would have thought though if you show it something that looks nothing like those 2 items it would not recognise it instead of telling you it is always one of the two things? I would rather have a not recognised message than everything being an apple
– user8463989
Nov 12 at 19:48
I am not expecitng it to give me the correct names for something I haven't trained, but I am not expecting it to tell me everything is an apple but rather that it doesn't recognise something that isn't an apple or a banana
– user8463989
Nov 12 at 19:52
@user8463989 try edited answer
– Robert Dresler
Nov 12 at 20:11
thanks for that. It would have been perfect if the unknown images would score that low. I checked the scores and for a picture of a waterfall it seems to know with 100% certainty that it is an apple. So, that code of yours never fires.
– user8463989
Nov 13 at 8:05
@user8463989 If you print topResult.confidence right above if statement what is printed?
– Robert Dresler
Nov 13 at 8:36
|
show 3 more comments
If you have model trained with 2 items only (in your case Apple and Banana) you can't expect that your ML model recognize something else than these 2 items.
Code you wrote always return item which will have the biggest confidence.
If you want to return item just if topClassification with your testing image match at least for example 75% replace this
if classifications.isEmpty {
self.classificationLabel.text = "Nothing recognized"
} else {
//Display top classifications ranked by confidence in the UI
let topClassifications = classifications.prefix(1)
let descriptions = topClassifications.map { classification in
return String(format: " (%.2f) %@", classification.confidence, classification.identifier)
}
self.classificationLabel.text = descriptions.joined(separator: "n")
}
with
guard let topResult = classifications.first else { return }
if topResult.confidence > 0.75 {
print(topResult.identifier)
} else {
print("Match is less than 75%")
}
I would have thought though if you show it something that looks nothing like those 2 items it would not recognise it instead of telling you it is always one of the two things? I would rather have a not recognised message than everything being an apple
– user8463989
Nov 12 at 19:48
I am not expecitng it to give me the correct names for something I haven't trained, but I am not expecting it to tell me everything is an apple but rather that it doesn't recognise something that isn't an apple or a banana
– user8463989
Nov 12 at 19:52
@user8463989 try edited answer
– Robert Dresler
Nov 12 at 20:11
thanks for that. It would have been perfect if the unknown images would score that low. I checked the scores and for a picture of a waterfall it seems to know with 100% certainty that it is an apple. So, that code of yours never fires.
– user8463989
Nov 13 at 8:05
@user8463989 If you print topResult.confidence right above if statement what is printed?
– Robert Dresler
Nov 13 at 8:36
|
show 3 more comments
If you have model trained with 2 items only (in your case Apple and Banana) you can't expect that your ML model recognize something else than these 2 items.
Code you wrote always return item which will have the biggest confidence.
If you want to return item just if topClassification with your testing image match at least for example 75% replace this
if classifications.isEmpty {
self.classificationLabel.text = "Nothing recognized"
} else {
//Display top classifications ranked by confidence in the UI
let topClassifications = classifications.prefix(1)
let descriptions = topClassifications.map { classification in
return String(format: " (%.2f) %@", classification.confidence, classification.identifier)
}
self.classificationLabel.text = descriptions.joined(separator: "n")
}
with
guard let topResult = classifications.first else { return }
if topResult.confidence > 0.75 {
print(topResult.identifier)
} else {
print("Match is less than 75%")
}
If you have model trained with 2 items only (in your case Apple and Banana) you can't expect that your ML model recognize something else than these 2 items.
Code you wrote always return item which will have the biggest confidence.
If you want to return item just if topClassification with your testing image match at least for example 75% replace this
if classifications.isEmpty {
self.classificationLabel.text = "Nothing recognized"
} else {
//Display top classifications ranked by confidence in the UI
let topClassifications = classifications.prefix(1)
let descriptions = topClassifications.map { classification in
return String(format: " (%.2f) %@", classification.confidence, classification.identifier)
}
self.classificationLabel.text = descriptions.joined(separator: "n")
}
with
guard let topResult = classifications.first else { return }
if topResult.confidence > 0.75 {
print(topResult.identifier)
} else {
print("Match is less than 75%")
}
edited Nov 13 at 8:14
answered Nov 12 at 19:45
Robert Dresler
3,9651526
3,9651526
I would have thought though if you show it something that looks nothing like those 2 items it would not recognise it instead of telling you it is always one of the two things? I would rather have a not recognised message than everything being an apple
– user8463989
Nov 12 at 19:48
I am not expecitng it to give me the correct names for something I haven't trained, but I am not expecting it to tell me everything is an apple but rather that it doesn't recognise something that isn't an apple or a banana
– user8463989
Nov 12 at 19:52
@user8463989 try edited answer
– Robert Dresler
Nov 12 at 20:11
thanks for that. It would have been perfect if the unknown images would score that low. I checked the scores and for a picture of a waterfall it seems to know with 100% certainty that it is an apple. So, that code of yours never fires.
– user8463989
Nov 13 at 8:05
@user8463989 If you print topResult.confidence right above if statement what is printed?
– Robert Dresler
Nov 13 at 8:36
|
show 3 more comments
I would have thought though if you show it something that looks nothing like those 2 items it would not recognise it instead of telling you it is always one of the two things? I would rather have a not recognised message than everything being an apple
– user8463989
Nov 12 at 19:48
I am not expecitng it to give me the correct names for something I haven't trained, but I am not expecting it to tell me everything is an apple but rather that it doesn't recognise something that isn't an apple or a banana
– user8463989
Nov 12 at 19:52
@user8463989 try edited answer
– Robert Dresler
Nov 12 at 20:11
thanks for that. It would have been perfect if the unknown images would score that low. I checked the scores and for a picture of a waterfall it seems to know with 100% certainty that it is an apple. So, that code of yours never fires.
– user8463989
Nov 13 at 8:05
@user8463989 If you print topResult.confidence right above if statement what is printed?
– Robert Dresler
Nov 13 at 8:36
I would have thought though if you show it something that looks nothing like those 2 items it would not recognise it instead of telling you it is always one of the two things? I would rather have a not recognised message than everything being an apple
– user8463989
Nov 12 at 19:48
I would have thought though if you show it something that looks nothing like those 2 items it would not recognise it instead of telling you it is always one of the two things? I would rather have a not recognised message than everything being an apple
– user8463989
Nov 12 at 19:48
I am not expecitng it to give me the correct names for something I haven't trained, but I am not expecting it to tell me everything is an apple but rather that it doesn't recognise something that isn't an apple or a banana
– user8463989
Nov 12 at 19:52
I am not expecitng it to give me the correct names for something I haven't trained, but I am not expecting it to tell me everything is an apple but rather that it doesn't recognise something that isn't an apple or a banana
– user8463989
Nov 12 at 19:52
@user8463989 try edited answer
– Robert Dresler
Nov 12 at 20:11
@user8463989 try edited answer
– Robert Dresler
Nov 12 at 20:11
thanks for that. It would have been perfect if the unknown images would score that low. I checked the scores and for a picture of a waterfall it seems to know with 100% certainty that it is an apple. So, that code of yours never fires.
– user8463989
Nov 13 at 8:05
thanks for that. It would have been perfect if the unknown images would score that low. I checked the scores and for a picture of a waterfall it seems to know with 100% certainty that it is an apple. So, that code of yours never fires.
– user8463989
Nov 13 at 8:05
@user8463989 If you print topResult.confidence right above if statement what is printed?
– Robert Dresler
Nov 13 at 8:36
@user8463989 If you print topResult.confidence right above if statement what is printed?
– Robert Dresler
Nov 13 at 8:36
|
show 3 more comments
In a model that is a classifier, you always get just as many VNClassificationObservation
objects as there are classes. No more, no less. The array is only empty if there was a problem running the model.
add a comment |
In a model that is a classifier, you always get just as many VNClassificationObservation
objects as there are classes. No more, no less. The array is only empty if there was a problem running the model.
add a comment |
In a model that is a classifier, you always get just as many VNClassificationObservation
objects as there are classes. No more, no less. The array is only empty if there was a problem running the model.
In a model that is a classifier, you always get just as many VNClassificationObservation
objects as there are classes. No more, no less. The array is only empty if there was a problem running the model.
answered Nov 13 at 9:44
Matthijs Hollemans
2,6981210
2,6981210
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%2f53268919%2fcoreml2-keeps-telling-me-everything-is-the-same-thing%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
1
create one more item called Unknowned
– canister_exister
Nov 12 at 19:52
That's worth a shot.
– user8463989
Nov 12 at 19:54