Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

WIP and proof of concept: convert R models to coreml and back

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md
Notifications You must be signed in to change notification settings

dirkschumacher/coreml

Repository files navigation

coreml

The goal of coreml is to convert models trained/fitted in R to coreml so that you can use them in Apple iOS applications.

This is work in progress and just a proof of concept. Do not use it for production, it barely works and I am still learning and testing.

Installation

remotes::install_github("dirkschumacher/coreml")

API

The API can and will change.

  • coreml_convert convert a R model to coreml
  • coreml_predict make predictions with a coreml model (just a proof of concept)
  • coreml_save save a coreml model to disk as binary data
  • coreml_load load a coreml model from disk
  • convert_keras convert a keras model to coreml using coremltools. This does not work at the moment.

Example

Here we convert a logistic regression model (GLM with family=binomial) to a coreml model. Save it to disk, read it in again and make predictions.

  library(coreml)
  model <- glm(I(mpg >= 20) ~ -1 + hp + cyl + drat, data = mtcars, family = binomial())

  coreml_model <- coreml_convert(model)
  
  path <- file.path(tempdir(), "test.mlmodel")
  
  coreml_save(coreml_model, path)

  mod <- coreml_load(path)

  newdata <- as.matrix(mtcars[, c("hp", "cyl", "drat")])
  
  all.equal(
    coreml_predict(mod, newdata),
    predict(model, mtcars, type = "response")
  )
#> [1] TRUE

About

WIP and proof of concept: convert R models to coreml and back

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENSE
MIT
LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages