Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:(format): add pickle format #183

Merged
merged 1 commit into from
Jul 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added examples/Pickle-model/model/model.pickle
Binary file not shown.
2 changes: 2 additions & 0 deletions examples/Pickle-model/ormbfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
author: "Geoffrey Bolmier <[email protected]>"
format: Pickle
16 changes: 16 additions & 0 deletions pkg/model/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
FormatSKLearn Format = "SKLearn"
FormatXGBoost Format = "XGBoost"
FormatMLflow Format = "MLflow"
FormatPickle Format = "Pickle"
FormatOthers Format = "Others"
)

Expand Down Expand Up @@ -67,6 +68,8 @@ func (f Format) ValidateDirectory(rootPath string) error {
err = f.validateForXGBoost(modelFilePath, fileList)
case FormatMLflow:
err = f.validateForMLflow(modelFilePath, fileList)
case FormatPickle:
err = f.validateForPickle(modelFilePath, fileList)
case FormatOthers:
return nil
default:
Expand Down Expand Up @@ -275,3 +278,16 @@ func (f Format) validateForMLflow(modelPath string, files []os.FileInfo) error {
}
return nil
}

func (f Format) validateForPickle(modelPath string, files []os.FileInfo) error {
var pickleFileNum int32
for _, file := range files {
if path.Ext(file.Name()) == ".pickle" {
pickleFileNum++
}
}
if e := ValidateError(modelPath, "*.pickle", pickleFileNum); e != nil {
return e
}
return nil
}
6 changes: 6 additions & 0 deletions pkg/model/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@ var _ = Describe("Format", func() {
Expect(err).To(BeNil())
})

It("Should validate Pickle format successfully", func() {
pickleFormat := model.FormatPickle
err := pickleFormat.ValidateDirectory("../../examples/Pickle-model")
Expect(err).To(BeNil())
})

It("Should validate Others for corruptted format successfully", func() {
others := model.FormatOthers
err := others.ValidateDirectory("../../test/Corrupt")
Expand Down