apple / coremltools

Core ML tools contain supporting tools for Core ML model conversion, editing, and validation.
https://coremltools.readme.io
BSD 3-Clause "New" or "Revised" License
4.35k stars 628 forks source link

Access Layers of a model within a pipeline #589

Closed osianSmith closed 4 years ago

osianSmith commented 4 years ago

❓Question

Hey, I have a SoudAnaysisis model (created by CreateML) and I want to access GLM classifier and replace it with my own model. However, when using CoreMlTools there does not seem to be a method for me to access the layers. When I try to loop over layers I get 0 layers. Is there any way for me to access these layers? Here is my code:

import sys, coremltools

model = coremltools.models.MLModel("model.mlmodel")
spec = model.get_spec() # gets a deep copy

spec = coremltools.utils.load_spec("model.mlmodel")
print(spec.description)
print(spec.WhichOneof("Type"))

for layer in spec.neuralNetworkClassifier.layers: 
    print(layer.name)

System Information

Any help will be appreciated

Osian

osianSmith commented 4 years ago

Hey I found the solution here

https://github.com/apple/coremltools/issues/427

I'll close this as It's now resolved