Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Can't export activity classifier to CoreML. #2945

Closed
mecid opened this issue Jan 22, 2020 · 8 comments · Fixed by #2991
Closed

Can't export activity classifier to CoreML. #2945

mecid opened this issue Jan 22, 2020 · 8 comments · Fixed by #2991

Comments

@mecid
Copy link

mecid commented Jan 22, 2020

Can't export activity classifier to CoreML. It works well with TuriCreate 5, broken with 6.0.

turicreate.toolkits._main.ToolkitError: Could not export model: validator error: Layer 'features' of type 320 has 1 inputs but expects at least 2.

@mecid mecid changed the title Can't export to CoreML Can't export activity classifier to CoreML. Jan 22, 2020
@syoutsey
Copy link
Collaborator

syoutsey commented Jan 22, 2020

Hi @mecid are you able to share the model you're trying to export?

@mecid
Copy link
Author

mecid commented Jan 23, 2020

@syoutsey I'm not sure that I can share the model, but here is the code which I use to train and export model.

`
import turicreate as tc

data = tc.SFrame('data.sframe')

train, test = tc.activity_classifier.util.random_split_by_session(data, session_id = 'day', fraction=0.8)
model = tc.activity_classifier.create(train, session_id='day', target='activity', prediction_window=1)

metrics = model.evaluate(test)
model.save('RawSleepClassifier.model')
model.export_coreml('RawSleepClassifier.mlmodel')
`

@TobyRoseman
Copy link
Collaborator

I just tried exporting an activity classifier model with 6.0 and it worked for me.

@mecid - Can you tell us a bit more about your dataset? Roughly how many row and columns? What are the types of your columns?

@mecid
Copy link
Author

mecid commented Jan 28, 2020

@TobyRoseman my dataset looks like this

`
day,value,activity

1,7.49629198749759,1
`

@TobyRoseman
Copy link
Collaborator

@mecid - thank you for the information. I'm now able to reproduce the issue.

This issue seems to be happening when ever there is only one feature column. Something in the Activity Classifier's export_coreml seems to be incorrectly assuming there will alway be more than one feature column.

The easiest way to reproduce this error is to use the HAPT Dataset and the following code:

import turicreate as tc
data = tc.load_sframe('./hapt_data.sframe/')
data = data.remove_columns(['acc_y', 'acc_z', 'gyro_x', 'gyro_y', 'gyro_z'])
model = tc.activity_classifier.create(data, session_id='exp_id', target='activity',
                                      prediction_window=50)
model.export_coreml('MyCustomActivityClassifier.mlmodel')

@TobyRoseman TobyRoseman added this to the 6.2 milestone Jan 29, 2020
@mecid
Copy link
Author

mecid commented Jan 30, 2020

@TobyRoseman awesome! Do we have any workaround?

@TobyRoseman
Copy link
Collaborator

@mecid - for a workaround you could add a column to your dataset which just always has the same constant for each row (i.e. data['constantColumn'] = 1).

I've tested doing this with the HAPT Dataset. Doing this doesn't seem to affect the test accuracy. I'd recommend you verify that's true for your dataset too.

Also you'll need to add the constant column to any prediction calls to your exported CoreML model.

@mecid
Copy link
Author

mecid commented Jan 31, 2020

@TobyRoseman nice, thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants