coremltools | Core ML tools contain supporting tools for Core ML model | Machine Learning library

 by   apple Python Version: 8.0b1 License: BSD-3-Clause

kandi X-RAY | coremltools Summary

kandi X-RAY | coremltools Summary

coremltools is a Python library typically used in Artificial Intelligence, Machine Learning, Deep Learning, Pytorch, Tensorflow applications. coremltools has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has high support. You can install using 'pip install coremltools' or download it from GitHub, PyPI.

Core ML tools contain supporting tools for Core ML model conversion, editing, and validation.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              coremltools has a highly active ecosystem.
              It has 3392 star(s) with 527 fork(s). There are 115 watchers for this library.
              There were 2 major release(s) in the last 6 months.
              There are 211 open issues and 950 have been closed. On average issues are closed in 248 days. There are 19 open pull requests and 0 closed requests.
              It has a positive sentiment in the developer community.
              The latest version of coremltools is 8.0b1

            kandi-Quality Quality

              coremltools has 0 bugs and 0 code smells.

            kandi-Security Security

              coremltools has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              coremltools code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              coremltools is licensed under the BSD-3-Clause License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              coremltools releases are available to install and integrate.
              Deployable package is available in PyPI.
              Build file is available. You can build the component from source.
              Installation instructions are not available. Examples and code snippets are available.

            Top functions reviewed by kandi - BETA

            kandi has reviewed coremltools and discovered the below as its top functions. This is intended to give you an instant insight into coremltools implemented functionality, and help decide if they suit your requirements.
            • Perform quantization on the nn_spec .
            • Converts LSTM to LSTM
            • Converts a model into Keras model .
            • Convert a source to a model .
            • Add a convolution .
            • Converts a model to a spec model .
            • Convert a sklearn model to a skk model .
            • Convert LSTM to LSTM
            • Re - allocates the tensor array .
            • Checks whether the feature list is valid or not
            Get all kandi verified functions for this library.

            coremltools Key Features

            No Key Features are available at this moment for coremltools.

            coremltools Examples and Code Snippets

            copy iconCopy
            # pip install tensorflow==1.1.0
            # pip install keras==2.0.4
            # pip install coremltools==0.4.0
            pip install -r requirements.txt
              
            How to replace torch.sparse with other pytorch function?
            Pythondot img2Lines of Code : 15dot img2License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            def dense_from_coo(i, v):
                rows = i[0].max()+1
                cols = i[1].max()+1
                out = torch.zeros(rows, cols)
                out[i[0], i[1]] = v
                return out
            
            print(dense_from_coo(i,v))
            >>> tensor([[0., 0., 3.],
                        [4., 0., 5.]])
            
            p
            Traffic sign recognition iOS CoreML - label not showing class
            Pythondot img3Lines of Code : 3dot img3License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            class_labels = list(range(1, 43))
            class_labels = [str(x) for x in class_labels]   # add this line
            
            virtualenv and Pycharm: folders, and packages: how does it work?
            Pythondot img4Lines of Code : 4dot img4License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            source path_to_virtualenv/bin/activate
            
            pip install 
            
            Why Can't I Use Images With CoreMLTools In Python 3?
            Pythondot img5Lines of Code : 10dot img5License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            model.predict( {"img": img } )
            
            input {
              name: "image"
              shortDescription: "Input image to be classified"
              ....
            }
            
            model.predict( {"image": img} )
            
            AttributeError: 'InputLayer' object has no attribute 'inbound_nodes'
            Pythondot img6Lines of Code : 2dot img6License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            pip install -U git+https://github.com/apple/coremltools.git
            
            Coremltools converting caffemodel issue
            Pythondot img7Lines of Code : 6dot img7License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            input: "data"
            input_dim: 1
            input_dim: 3
            input_dim: 224
            input_dim: 224
            
            coremltools: how to properly use NeuralNetworkMultiArrayShapeRange?
            Pythondot img8Lines of Code : 2dot img8License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            del spec.description.input[0].shape[0]
            
            copy iconCopy
            import coremltools
            
            category_output_labels = ['dress', 'shirt', 'trousers']
            color_output_labels = ['black', 'blue', 'green', 'pink', 'red', 
            'white']
            
            coreml_model = coremltools.converters.keras.convert('./fashion_multi_output_v02.h5',
            
            Error installing coremltools
            Pythondot img10Lines of Code : 16dot img10License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            pip install --upgrade pip
            
            pip install –U virtualenv
            
            cd ~
            virtualenv coreml
            
            source coreml/bin/activate
            
            pip install -U coremltools
            

            Community Discussions

            QUESTION

            How to replace torch.sparse with other pytorch function?
            Asked 2021-May-20 at 12:48

            I would like to replace the torch.sparse function using the other Pytorch function.

            ...

            ANSWER

            Answered 2021-May-20 at 12:48

            If I understand sparse_coo format correctly, the two rows of i are just the coordinates at which to copy the values of v. Which means that you can instead create you matrix like :

            Source https://stackoverflow.com/questions/67620416

            QUESTION

            How to replace torch.norm with other pytorch function?
            Asked 2021-May-09 at 15:57

            I would like to replace the torch.norm function using the other Pytorch function.

            I was able to replace torch.norm in the case where x is not a matrix, as shown in the following code.

            ...

            ANSWER

            Answered 2021-May-09 at 15:57

            You could try the following:

            Source https://stackoverflow.com/questions/67456870

            QUESTION

            Trying to convert model to coreml with coremltools 4.1 NOT WORKING
            Asked 2021-Apr-23 at 10:27

            I am converting my model to coreml using coremltools 4.1 and for some reason I am getting this error: TypeError: 'InputLayer' object is not iterable and on line coreml_model = coremltools.converters.keras.convert(model). can anyone what I have done wrong in my code. thanks for the help. here is my snippet.

            ...

            ANSWER

            Answered 2021-Apr-23 at 10:27

            Don't use coremltools.converters.keras.convert but coremltools.convert(...). See the docs for details: https://coremltools.readme.io/docs/introductory-quickstart

            Source https://stackoverflow.com/questions/67222236

            QUESTION

            Custom CoreML output layer that sums multiArray output
            Asked 2021-Apr-02 at 03:03

            Please bear with me. I'm new to CoreML and machine learning. I have a CoreML model that I was able to convert from a research paper implementation that used Caffe. It's a CSRNet, the objective being crowd-counting. After much wrangling, I'm able to load the MLmodel into Python using Coremltools, pre-process an image using Pillow and predict an output. The result is a MultiArray (from a density map), which I've then processed further to derive the actual numerical prediction.

            How do I add a custom layer as an output to the model that takes the current output and performs the following functionality? I've read numerous articles, and am still at a loss. (Essentially, it sums the values all the values in the MultiArray) I'd like to be able to save the model/ layer and import it into Xcode so that the MLModel result is a single numerical value, and not a MultiArray.

            This is the code I'm currently using to convert the output from the model into a number (in Python):

            ...

            ANSWER

            Answered 2021-Apr-01 at 10:21

            You can add a ReduceSumLayerParams to the end of the model. You'll need to do this in Python by hand. If you set its reduceAll parameter to true, it will compute the sum over the entire tensor.

            However, in my opinion, it's just as easy to use the model as-is, and in your Swift code grab a pointer to the MLMultiArray's data and use vDSP.sum(a) to compute the sum.

            Source https://stackoverflow.com/questions/66898082

            QUESTION

            Instance Normalization Error while converting model from tensorflow to Coreml (4.0)
            Asked 2021-Jan-28 at 18:12

            I try to convert my model from Tensorflow to Coreml however I get below error. Isn't it possible to convert instance normalization layer to CoreML? Any workaround to overcome?

            ValueError Traceback (most recent call last) in () 6 7 model = ct.convert( ----> 8 tf_keras_model )

            6 frames /usr/local/lib/python3.6/dist-packages/coremltools/converters/mil/mil/block.py in remove_ops(self, existing_ops) 700 + "used by ops {}" 701 ) --> 702 raise ValueError(msg.format(op.name, i, v.name, child_op_names)) 703 # Check that the output Var isn't block's output 704 if v in self._outputs:

            ValueError: Cannot delete op 'Generator/StatefulPartitionedCall/StatefulPartitionedCall/encoder_down_resblock_0/instance_norm_0/Shape' with active output at id 0: 'Generator/StatefulPartitionedCall/StatefulPartitionedCall/encoder_down_resblock_0/instance_norm_0/Shape' used by ops ['Generator/StatefulPartitionedCall/StatefulPartitionedCall/encoder_down_resblock_0/instance_norm_0/strided_slice'] SEARCH STACK OVERFLOW

            ...

            ANSWER

            Answered 2021-Jan-28 at 18:12

            I use keras-contrib instead and it works fine. Please see issue and its solution below. It is still open for tensorflow_addons.

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

            Source https://stackoverflow.com/questions/65903070

            QUESTION

            Traffic sign recognition iOS CoreML - label not showing class
            Asked 2020-Nov-17 at 23:04

            I am following this tutorial to build a simple deep learning app for traffic sign recognition. link

            I made an own model, and I also tried it with the model in this repository: link

            When I run the app from xcode on my iPhone, I can see the picture of the camera, but the text always says "Label", no matter what is on the screen. The only thing I modified from the tutorial is that I hardcoded the classes before converting to mlmodel:

            ...

            ANSWER

            Answered 2020-Nov-17 at 10:16

            I don't know if this fixes it, but in your conversion script try the following:

            Source https://stackoverflow.com/questions/64861418

            QUESTION

            Coremltools error while converting: "'str' object has no attribute 'decode'"
            Asked 2020-Nov-10 at 11:37

            I am trying to use coremltools to convert a keras model to mlmodel. I am getting the following code:

            ...

            ANSWER

            Answered 2020-Nov-10 at 11:37

            it seems to be an issue related to a recent release of version 3.0.0 of h5yp, so either you can use a previous version of h5yp (pip install tensorflow h5py<3.0.0) or you can try to remove .decode('utf-8') from tensorflow/python/keras/saving/hdf5_format.py. I know they are not the answer you are looking for but seems to be the way out. Otherwise you can just wait for an update.

            Source https://stackoverflow.com/questions/64767814

            QUESTION

            How to access the model's description in CoreML?
            Asked 2020-Oct-28 at 10:36

            I have a CoreML model and I've added information to the model using coremltools:

            ...

            ANSWER

            Answered 2020-Oct-28 at 10:36

            MyModel is not an MLModel object but a class that is specifically generated for your model. However, it does have an MLModel object inside, in the model property.

            You can access the description like so:

            Source https://stackoverflow.com/questions/64557021

            QUESTION

            MLModel works with MultiArray output but cannot successfully change the output to an image
            Asked 2020-Oct-07 at 09:55

            I have converted a Keras model to a MLModel using coremltools 4.0 with limited success.

            It works but only if I use an MLMultiArray for the output and covert to an image. Converting to an image takes magnitudes longer than inferencing; making it unusable.

            If I try to change the MLModel spec to use images for output I get this error running prediction:

            Failed to convert output Identity to image:

            NSUnderlyingError=0x2809bad00 {Error Domain=com.apple.CoreML Code=0 "Invalid array shape ( 2048, 2048, 3 ) for converting to gray image"

            Even though I have specified RGB for the output color:

            output { name: "Identity" type { imageType { width: 2048 height: 2048 colorSpace: RGB } } }

            If I use a MultiArray (that works) Xcode reports:

            output: Float32 1 x 2048 x 2048 x 3 array

            I suspect the issue is the first dimension, which is the batch number but no dimensions are shown, so I can't delete the batch dimension:

            output { name: "Identity" type { multiArrayType { dataType: FLOAT32 } } }

            I don't think I can just add an output shape to the Keras Conv2D output layer because it has multiple inbound nodes with different shapes. Here are the output shapes:

            ...

            ANSWER

            Answered 2020-Jul-21 at 09:17

            In Core ML the order of the dimensions is (channels, height, width) so it expects to see a 3 x 2048 x 2048 output instead of 2048 x 2048 x 3.

            Note that you also need to make sure the output pixels are in the range [0, 255] instead of [0, 1] which is probably what your Keras model gives you.

            Source https://stackoverflow.com/questions/63006397

            QUESTION

            CoreML automatic cast int to float
            Asked 2020-Sep-19 at 11:47

            I am new user of coremltool, currently I am able to convert my TF model, and run it in python. However the output layer of my model is automatically converted to float instead of int32. I have to perform myself in python a rollback conversion.

            ...

            ANSWER

            Answered 2020-Sep-19 at 11:47

            You can change the datatype of the model's outputs to INT32 using the coremltools Python library. That will automatically cast those numbers from floats to integers.

            Something like this:

            Source https://stackoverflow.com/questions/63953344

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install coremltools

            You can install using 'pip install coremltools' or download it from GitHub, PyPI.
            You can use coremltools like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            Install
          • PyPI

            pip install coremltools

          • CLONE
          • HTTPS

            https://github.com/apple/coremltools.git

          • CLI

            gh repo clone apple/coremltools

          • sshUrl

            git@github.com:apple/coremltools.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link