Optimize your Core ML usage

RSS for tag

Discuss the WWDC22 Session Optimize your Core ML usage

Posts under wwdc2022-10027 tag

10 Posts

Post

Replies

Boosts

Views

Activity

Getting ValueError: Categorical Cross Entropy loss layer input (Identity) must be a softmax layer output.
I am working on the neural network classifier provided on the coremltools.readme.io in the updatable->neural network section(https://coremltools.readme.io/docs/updatable-neural-network-classifier-on-mnist-dataset). I am using the same code but I get an error saying that the coremltools.converters.keras.convert does not exist. But this I know can be coreml version issue. Right know I am using coremltools version 6.2. I converted this model to mlmodel with .convert only. It got converted successfully. But I face an error in the make_updatable function saying the loss layer must be softmax output. Even the coremlt package API reference there I found its because the layer name is softmaxND but it should be softmax. Now the problem is when I convert the model from Keras sequential model to coreml model. the layer name and type change. And the softmax changes to softmaxND. Does anyone faced this issue? if I execute this builder.inspect_layers(last=4) I get this output [Id: 32], Name: sequential/dense_1/Softmax (Type: softmaxND) Updatable: False Input blobs: ['sequential/dense_1/MatMul'] Output blobs: ['Identity'] [Id: 31], Name: sequential/dense_1/MatMul (Type: batchedMatmul) Updatable: False Input blobs: ['sequential/dense/Relu'] Output blobs: ['sequential/dense_1/MatMul'] [Id: 30], Name: sequential/dense/Relu (Type: activation) Updatable: False Input blobs: ['sequential/dense/MatMul'] Output blobs: ['sequential/dense/Relu'] In the make_updatable function when I execute builder.set_categorical_cross_entropy_loss(name='lossLayer', input='Identity') I get this error ValueError: Categorical Cross Entropy loss layer input (Identity) must be a softmax layer output.
2
0
1.5k
Nov ’24
Not sure if the cpu percentage is normal
The previous question haven't been solved. I send it again. when my video neural network model was running on iphone11, the cpu occupation reached to 31%, is it normal? I am not sure if the value 31% has a serious impact on the other app. So that I would ask for your advice. Previously, I originally expected to lower the cpu percentage by reducing the model op. when I put a model with only 6 biliear_interpolation ops into coreml, the cpu percentage is 20%(equal on cpu, cpuandgpu&all), so I consider if the only coreML scheduling occupy the 20% cpu?
0
0
723
Mar ’23
Creating MLMultiArray from IOSurface backed CVPixelBuffer fixes strides to multiples of 32
Hi, I have found that when creating a MLMultiArray from an IOSurface backed CVPixelBuffer that the striding across the last dimension gets fixed to a multiple of 32. Say I have some objective-c code that creates a MLMultiArray from a CVPixelBuffer like so; CVPixelBufferRef pixelBuffer = NULL; NSDictionary* pixelBufferAttributes = @{ (id)kCVPixelBufferIOSurfacePropertiesKey: @{} }; // Since shape == [2, 3, 4], width is 4 (= shape[2]) and height is 6 (= shape[0] * shape[1]). CVPixelBufferCreate(kCFAllocatorDefault, 4, 6, kCVPixelFormatType_OneComponent16Half, (__bridge CFDictionaryRef)pixelBufferAttributes, &pixelBuffer); MLMultiArray *multiArray = [[MLMultiArray alloc] initWithPixelBuffer:pixelBuffer shape:@[@2, @3, @4]]; This successfully creates a MLMultiArray from an IOSurface backed CVPixelBuffer. If I inspect the MLMultiArray, I see that the shape and strides are the following; //_shape: [2, 3, 4] //_strides: [96, 32, 1] To me it makes more sense that the strides should be; //_strides: [12,4,1] I assume that this is likely hardcoded to be multiples of 32 somewhere in the MLMultiArray initialisation code and since strides is a read only member variable of MLMultiArray it cannot be changed explicitly. Is it possible to set the striding explicitly in any way, or create an MLMutliArray from IOSurface backed buffer that allows the striding to be set differently ?
1
0
1.8k
Aug ’22
Allow 16-bit RGBA image formats as input/output of MLModels
Starting in iOS 16 and macOS Ventura, OneComponent16Half will be a new scalar type for Images. Ideally, we would also like to use the 16-bit support for RGBA images. As of now, we need to make an indirection using MLMultiArray with Float (Float16 with the update) set as type and copy the data into the desired image buffer. Direct usage of 16-bit RGBA predictions in Image format would be ideal for some applications requiring high precision outputs, like models that are trained on EDR image data. This is also useful when integrating Core ML into Core Image pipelines since CI’s internal image format is 16-bit RGBA by default. When passing that into a Neural Style Transfer model with (8-bit) RGBA image input/output type, conversions are always necessary (as demonstrated in WWDC2022-10027). If we could modify the models to use 16-bit RGBA images instead, no conversion would be necessary anymore. Thanks for the consideration!
3
0
1.4k
Jun ’22
Getting ValueError: Categorical Cross Entropy loss layer input (Identity) must be a softmax layer output.
I am working on the neural network classifier provided on the coremltools.readme.io in the updatable->neural network section(https://coremltools.readme.io/docs/updatable-neural-network-classifier-on-mnist-dataset). I am using the same code but I get an error saying that the coremltools.converters.keras.convert does not exist. But this I know can be coreml version issue. Right know I am using coremltools version 6.2. I converted this model to mlmodel with .convert only. It got converted successfully. But I face an error in the make_updatable function saying the loss layer must be softmax output. Even the coremlt package API reference there I found its because the layer name is softmaxND but it should be softmax. Now the problem is when I convert the model from Keras sequential model to coreml model. the layer name and type change. And the softmax changes to softmaxND. Does anyone faced this issue? if I execute this builder.inspect_layers(last=4) I get this output [Id: 32], Name: sequential/dense_1/Softmax (Type: softmaxND) Updatable: False Input blobs: ['sequential/dense_1/MatMul'] Output blobs: ['Identity'] [Id: 31], Name: sequential/dense_1/MatMul (Type: batchedMatmul) Updatable: False Input blobs: ['sequential/dense/Relu'] Output blobs: ['sequential/dense_1/MatMul'] [Id: 30], Name: sequential/dense/Relu (Type: activation) Updatable: False Input blobs: ['sequential/dense/MatMul'] Output blobs: ['sequential/dense/Relu'] In the make_updatable function when I execute builder.set_categorical_cross_entropy_loss(name='lossLayer', input='Identity') I get this error ValueError: Categorical Cross Entropy loss layer input (Identity) must be a softmax layer output.
Replies
2
Boosts
0
Views
1.5k
Activity
Nov ’24
Not sure if the cpu percentage is normal
The previous question haven't been solved. I send it again. when my video neural network model was running on iphone11, the cpu occupation reached to 31%, is it normal? I am not sure if the value 31% has a serious impact on the other app. So that I would ask for your advice. Previously, I originally expected to lower the cpu percentage by reducing the model op. when I put a model with only 6 biliear_interpolation ops into coreml, the cpu percentage is 20%(equal on cpu, cpuandgpu&all), so I consider if the only coreML scheduling occupy the 20% cpu?
Replies
0
Boosts
0
Views
723
Activity
Mar ’23
Not sure if the cpu percentage is normal
when my video neural network model was running on iphone11, the cpu occupation reached to 31%, is it normal?
Replies
3
Boosts
0
Views
906
Activity
Mar ’23
Performace tab missing inside the model viewer
I am not able to find the "Performace" tab in the Model viewer. Can anyone please help me in figuring out why that tab is missing
Replies
0
Boosts
0
Views
1.1k
Activity
Sep ’22
Model load on device during runtime
Using MlModelAsset and MlModel.load, can I load a model during runtime from my servers, or as a cloud kit asset instead of packaging the MlModel in my App?
Replies
2
Boosts
0
Views
1k
Activity
Aug ’22
Creating MLMultiArray from IOSurface backed CVPixelBuffer fixes strides to multiples of 32
Hi, I have found that when creating a MLMultiArray from an IOSurface backed CVPixelBuffer that the striding across the last dimension gets fixed to a multiple of 32. Say I have some objective-c code that creates a MLMultiArray from a CVPixelBuffer like so; CVPixelBufferRef pixelBuffer = NULL; NSDictionary* pixelBufferAttributes = @{ (id)kCVPixelBufferIOSurfacePropertiesKey: @{} }; // Since shape == [2, 3, 4], width is 4 (= shape[2]) and height is 6 (= shape[0] * shape[1]). CVPixelBufferCreate(kCFAllocatorDefault, 4, 6, kCVPixelFormatType_OneComponent16Half, (__bridge CFDictionaryRef)pixelBufferAttributes, &pixelBuffer); MLMultiArray *multiArray = [[MLMultiArray alloc] initWithPixelBuffer:pixelBuffer shape:@[@2, @3, @4]]; This successfully creates a MLMultiArray from an IOSurface backed CVPixelBuffer. If I inspect the MLMultiArray, I see that the shape and strides are the following; //_shape: [2, 3, 4] //_strides: [96, 32, 1] To me it makes more sense that the strides should be; //_strides: [12,4,1] I assume that this is likely hardcoded to be multiples of 32 somewhere in the MLMultiArray initialisation code and since strides is a read only member variable of MLMultiArray it cannot be changed explicitly. Is it possible to set the striding explicitly in any way, or create an MLMutliArray from IOSurface backed buffer that allows the striding to be set differently ?
Replies
1
Boosts
0
Views
1.8k
Activity
Aug ’22
Xcode coreml report not working on any 13+ macos version (beta/dev 1,2,3)
I have always same problem with error code 102 try both betas and dev version on macos (my iphone is always on newest beta also not working).
Replies
1
Boosts
1
Views
968
Activity
Jul ’22
Core ML Performance Report
Hi! Thank you for the Core ML Performance Report, it's a great tool! Is there a way to get peak memory footprint in addition to runtime? Thanks!
Replies
2
Boosts
0
Views
1.7k
Activity
Jun ’22
Allow 16-bit RGBA image formats as input/output of MLModels
Starting in iOS 16 and macOS Ventura, OneComponent16Half will be a new scalar type for Images. Ideally, we would also like to use the 16-bit support for RGBA images. As of now, we need to make an indirection using MLMultiArray with Float (Float16 with the update) set as type and copy the data into the desired image buffer. Direct usage of 16-bit RGBA predictions in Image format would be ideal for some applications requiring high precision outputs, like models that are trained on EDR image data. This is also useful when integrating Core ML into Core Image pipelines since CI’s internal image format is 16-bit RGBA by default. When passing that into a Neural Style Transfer model with (8-bit) RGBA image input/output type, conversions are always necessary (as demonstrated in WWDC2022-10027). If we could modify the models to use 16-bit RGBA images instead, no conversion would be necessary anymore. Thanks for the consideration!
Replies
3
Boosts
0
Views
1.4k
Activity
Jun ’22
Image Sharpening Model
Hi all Great talk! What image sharpening pytorch model did you use in the presentation/demo? thanks
Replies
1
Boosts
1
Views
1.5k
Activity
Jun ’22