Chain ML models

Hello guys,
How can I chain ML models? ex:
Model 1 indentify fruit: strawberry
Model 2 indentify strawberry type: strawberry apline
Model 3 indentify strawberry apline ripness level: very ripe strawberry apline
My coding is super limited. Im buikding models using Create ML, and replacing on Apple example app. If someone can send some code example I would higely appreciate!
Thanks

Accepted Reply

It seems for this use case you don't really want to "chain" models but rather persuite different execution paths inside your app. Here's some super-pseudo code for your use case:


let isStrawberry = model1.testForStrawberry(image)
if isStrawberry {
    let strawBerryType = model2.predictStrawberryTypes(image).getMostPropable()
    if stawBerryType == .apline {
        let ripeness = model3.predictAplineStrawberryRipeness(image)
        // do something with ripeness
    } else {
        // not a apline
    }
} else {
    // not a strawberry
}

Replies

It seems for this use case you don't really want to "chain" models but rather persuite different execution paths inside your app. Here's some super-pseudo code for your use case:


let isStrawberry = model1.testForStrawberry(image)
if isStrawberry {
    let strawBerryType = model2.predictStrawberryTypes(image).getMostPropable()
    if stawBerryType == .apline {
        let ripeness = model3.predictAplineStrawberryRipeness(image)
        // do something with ripeness
    } else {
        // not a apline
    }
} else {
    // not a strawberry
}

thanks a lot Frank, wull try it! : )
Do you know if it would also work if I have subfloders on the same ML model?

I'm afraid I don't know what you mean...