Platforms to show: All Mac Windows Linux Cross-Platform

/Mac64bit/CoreML/CoreML Model Info


Required plugins for this example: MBS Mac64bit Plugin, MBS Main Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Mac64bit/CoreML/CoreML Model Info

This example is the version from Tue, 16th Dec 2019.

Project "CoreML Model Info.xojo_binary_project"
Class App Inherits Application
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
EventHandler Sub NewDocument() dim f as FolderItem = SelectFolder 'GetOpenFolderItem(FileTypeGroup1.Model) if f <> nil then OpenDocument f end if End EventHandler
EventHandler Sub Open() #If Target64Bit And TargetMacOS Then // ok if not MLModelMBS.available then MsgBox "Please run on macOS High Sierra or newer." quit end if #else MsgBox "Please run in 64-bit Mac app" quit #endif End EventHandler
EventHandler Sub OpenDocument(item As FolderItem) if item.Name.Right(8) = ".mlmodel" then dim e as NSErrorMBS item = MLModelMBS.compileModelFile(item, e) if e <> nil then MsgBox "Failed to compile model."+EndOfLine+EndOfLine+e.LocalizedDescription Return end if end if // load model, to be specific: a mlmodelc folder dim e as NSErrorMBS dim m as MLModelMBS = MLModelMBS.modelWithContentsOfFile(item, e) if m = nil then MsgBox "Failed to load model."+EndOfLine+EndOfLine+e.LocalizedDescription return end if // show what we know dim w as new MainWindow dim list as listbox = w.List dim d as MLModelDescriptionMBS = m.modelDescription list.AddRow "filename", item.DisplayName list.AddRow "predictedFeatureName", d.predictedFeatureName list.AddRow "predictedProbabilitiesName", d.predictedProbabilitiesName list.AddFolder "inputDescriptionsByName", d.inputDescriptionsByName list.AddFolder "metadata", d.metadata list.AddFolder "outputDescriptionsByName", d.outputDescriptionsByName list.AddFolder "metadata", d.metadata // requires MacOS 10.15 If MLUpdateTaskMBS.available Then list.AddRow "isUpdatable", Str(d.isUpdatable) list.AddFolder "parameterDescriptionsByKey", d.parameterDescriptionsByKey list.AddFolder "trainingInputDescriptionsByName", d.trainingInputDescriptionsByName Else // older MacOS list.AddRow "isUpdatable", Str(False) End If End EventHandler
End Class
Class MainWindow Inherits Window
Control List Inherits Listbox
ControlInstance List Inherits Listbox
EventHandler Sub ExpandRow(row As Integer) Dim v As Variant = Me.RowTag(row) if v isa NSRangeMBS then dim k as NSRangeMBS = v list.AddRow "Location", str(k.Location) list.AddRow "Length", str(k.Length) elseif v isa MLImageConstraintMBS then dim k as MLImageConstraintMBS = v list.AddRow "pixelsWide", str(k.pixelsWide) list.AddRow "pixelsHigh", str(k.pixelsHigh) list.AddRow "pixelFormatType", hex(k.pixelFormatType) list.addFolder "sizeConstraint", k.sizeConstraint elseif v isa MLImageSizeConstraintMBS then dim k as MLImageSizeConstraintMBS = v list.AddRow "pixelsWideRange", k.pixelsWideRange list.AddRow "pixelsHighRange", k.pixelsHighRange dim t as string Select case k.type case MLImageSizeConstraintMBS.TypeUnspecified t = "Unspecified" case MLImageSizeConstraintMBS.TypeEnumerated t = "Enumerated" case MLImageSizeConstraintMBS.TypeRange t = "Range" end Select list.AddRow "type", str(k.type)+" "+t dim enumeratedImageSizes() as MLImageSizeMBS = k.enumeratedImageSizes dim u as integer = enumeratedImageSizes.Ubound for i as integer = 0 to u dim a as MLImageSizeMBS = enumeratedImageSizes(i) List.addFolder "size "+str(i), a next elseif v isa MLDictionaryConstraintMBS then dim k as MLDictionaryConstraintMBS = v dim t as string = KeyType(k.keyType) List.AddRow "keyType", str(k.keyType)+" "+t elseif v isa MLMultiArrayConstraintMBS then dim k as MLMultiArrayConstraintMBS = v dim t as string Select case k.dataType case MLMultiArrayMBS.DataTypeFloat32 t = "Float32" case MLMultiArrayMBS.DataTypeDouble t = "Double" case MLMultiArrayMBS.DataTypeInt32 t = "Int32" end select list.AddRow "dataType", hex(k.dataType)+" "+t dim shapes() as string dim shape() as Integer = k.shape for each s as integer in shape shapes.Append str(s) next list.AddRow "shape", join(shapes, ", ") list.addFolder "shapeConstraint", k.shapeConstraint elseif v isa MLNumericConstraintMBS then dim k as MLNumericConstraintMBS = v list.AddRow "minNumber", str(k.minNumber) list.AddRow "maxNumber", str(k.maxNumber) dim enumeratedNumberss() as string dim enumeratedNumbers() as Double = k.enumeratedNumbers for each s as integer in enumeratedNumbers enumeratedNumberss.Append str(s) next list.AddRow "Numbers", join(enumeratedNumberss, ", ") elseif v isa MLSequenceConstraintMBS then dim k as MLSequenceConstraintMBS = v list.AddRow "countRange", k.countRange list.addFolder "valueDescription", k.valueDescription elseif v isa MLSequenceMBS then dim k as MLSequenceMBS = v dim t as string = KeyType(k.type) List.AddRow "type", str(k.Type)+" "+t dim int64Valuess() as string dim int64Values() as Integer = k.int64Values for each s as integer in int64Values int64Valuess.Append str(s) next list.AddRow "int64Values", join(int64Valuess, ", ") dim stringValues() as string = k.stringValues list.AddRow "stringValues", join(stringValues, ", ") elseif v isa MLKeyMBS then dim k as MLKeyMBS = v list.AddRow "Name", k.Name list.AddRow "Scope", k.Scope elseif v isa MLImageSizeMBS then dim k as MLImageSizeMBS = v list.AddRow "pixelsWide", str(k.pixelsWide) list.AddRow "pixelsHigh", str(k.pixelsHigh) elseif v isa MLParameterDescriptionMBS then dim k as MLParameterDescriptionMBS = v list.AddFolder "Key", k.key list.AddRow "defaultValue", k.defaultValue list.AddFolder "numericConstraint", k.numericConstraint elseif v isa MLFeatureDescriptionMBS then dim md as MLFeatureDescriptionMBS = v if md <> nil then List.AddRow "name", md.Name dim t as string = KeyType(md.type) List.AddRow "type", str(md.Type)+" "+t dim o as string if md.isOptional then o = "Yes" else o = "No" end if List.AddRow "optional", o end if List.AddFolder "imageConstraint", md.imageConstraint List.AddFolder "dictionaryConstraint", md.dictionaryConstraint List.AddFolder "multiArrayConstraint", md.multiArrayConstraint List.AddFolder "sequenceConstraint", md.sequenceConstraint elseif v isa Dictionary then dim d as Dictionary = v for each key as Variant in d.keys dim val as Variant = d.Value(key) if VarType(val) = Variant.TypeObject then list.AddFolder key, val else List.AddRow key, val end if next else Break end if End EventHandler
End Control
Function KeyType(type as integer) As string dim t as string Select case type case MLFeatureValueMBS.TypeDictionary t = "Dictionary" case MLFeatureValueMBS.TypeDouble t = "Double" case MLFeatureValueMBS.TypeImage t = "Image" case MLFeatureValueMBS.TypeInt64 t = "Int64" case MLFeatureValueMBS.TypeInvalid t = "Invalid" case MLFeatureValueMBS.TypeMultiArray t = "MultiArray" case MLFeatureValueMBS.TypeString t = "String" case MLFeatureValueMBS.TypeSequence t = "Sequence" end Select return t End Function
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
FileTypeGroup1
Filetype CoreML Model
End FileTypeGroup1
Module Module1
Sub AddFolder(extends list as listbox, name as string, value as Variant) if value = nil then list.AddRow name, "n/a" else List.AddFolder name List.RowTag(List.LastIndex) = value end if End Sub
End Module
End Project

See also:

The items on this page are in the following plugins: MBS Mac64bit Plugin.


The biggest plugin in space...