Skip to content

princeSmall/CoreMLModel

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CoreMLModel

CoreML创建自己的.mlmodel的心酸历程,足足摆弄了半天,各种坑。

[Permission denied]问题

tools

  • pip install -U coremltools

  • 从图也可以看出coremltools包含numpy,six,protobuf,coremltools。 因为权限问题导致失败

  • sudo pip install -U coremltools
  • 遇到[Permission denied]都要加sudo

ImportError: No module named pkg_resources 问题

  • Step: 1 Login in root user.
sudo su root
  • Step: 2 Uninstall python-pip package if existing.
apt-get purge -y python-pip
  • Step: 3 Download files using wget command(File download in pwd )
wget https://bootstrap.pypa.io/get-pip.py
  • Step: 4 Run python file.
python ./get-pip.py
  • Step: 5 Finaly exicute installation command.
apt-get install python-pip
Note: User must be root.

好吧,这两个问题遍布整个流程,期间各种小问题我已经不记得了,接下来就开始正文了

  1. 下载coremltools
sudo pip install -U coremltools
  1. 下载pip.py文件
sudo python get-pip.py
  1. 下载scikit-learn
sudo pip install -U numpy scipy scikit-learn
  1. 下载panda
sudo pip install pandas

准备就绪,开工

创建csv文件

  1. csv文件属性Square_Feet,Price
  2. 记录文件所存储位置,调用的时候需要

在终端输入生成.mlmodel文件

  1. 导入需要的类
  2. 调用csv文件
  3. coremltools转换成.mlmodel文件
  4. author,license,description描述
  5. 输入Square_Feet,输出Price,保存
  • import coremltools

  • from sklearn.linear_model import LinearRegression

  • import pandas as pd

  • load data
  • data = pd.read_csv('/Users/sansi/Desktop/CoreMLModel/input_data.csv')

  • train a model
  • model = LinearRegression()

  • model.fit(data[["Square_Feet"]], data["Price"])

  • convert and save the scikit-learn model
  • coreml_model = coremltools.converters.sklearn.convert(model, "Square_Feet", "Price")

  • set model metadata
  • coreml_model.author = 'tongle'

  • coreml_model.license = 'BSD'

  • coreml_model.short_description = 'Predicts the price of a house in the Seattle area.'

  • set feature descriptions manually
  • coreml_model.input_description['Square_Feet'] = 'Size (in square feet)'

  • set the output descriptions
  • coreml_model.output_description['Price'] = 'Price of the house'

  • save the mdel
  • coreml_model.save('HousePricer.mlmodel')

如果没有一点python功底,我都要死在电脑前了,哈哈

About

自己创建CoreML 的 .mlmodel

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages