{"id":13717060,"url":"https://github.com/prisma-ai/torch2coreml","last_synced_at":"2026-01-14T10:22:46.016Z","repository":{"id":57476464,"uuid":"100525727","full_name":"prisma-ai/torch2coreml","owner":"prisma-ai","description":"Torch7 -\u003e CoreML","archived":true,"fork":false,"pushed_at":"2017-12-04T21:37:19.000Z","size":3275,"stargazers_count":386,"open_issues_count":13,"forks_count":55,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-08-18T14:54:19.004Z","etag":null,"topics":["ai","coreml","deep-learning","ios","ios11","neural-style","torch"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/prisma-ai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-16T19:36:23.000Z","updated_at":"2025-07-27T19:20:13.000Z","dependencies_parsed_at":"2022-09-12T14:33:54.064Z","dependency_job_id":null,"html_url":"https://github.com/prisma-ai/torch2coreml","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/prisma-ai/torch2coreml","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prisma-ai%2Ftorch2coreml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prisma-ai%2Ftorch2coreml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prisma-ai%2Ftorch2coreml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prisma-ai%2Ftorch2coreml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/prisma-ai","download_url":"https://codeload.github.com/prisma-ai/torch2coreml/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/prisma-ai%2Ftorch2coreml/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28417004,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T10:18:03.274Z","status":"ssl_error","status_checked_at":"2026-01-14T10:16:11.865Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","coreml","deep-learning","ios","ios11","neural-style","torch"],"created_at":"2024-08-03T00:01:17.494Z","updated_at":"2026-01-14T10:22:45.996Z","avatar_url":"https://github.com/prisma-ai.png","language":"Python","funding_links":[],"categories":["Pytorch \u0026 related libraries｜Pytorch \u0026 相关库","Pytorch \u0026 related libraries","Miscellaneous","Speech Processing","Core ML","Uncategorized"],"sub_categories":["Other libraries｜其他库:","Other libraries:","Tools","Uncategorized"],"readme":"# Convert Torch7 models into Apple CoreML format.\n\n[Short tutorial](https://blog.prismalabs.ai/diy-prisma-app-with-coreml-6b4994cc99e1)\n\nThis tool helps convert Torch7 models into [Apple CoreML](https://developer.apple.com/documentation/coreml) format which can then be run on Apple devices.\n\n![fast-neural-style example app screenshot](https://github.com/prisma-ai/torch2coreml/raw/master/screenshot.jpg \"fast-neural-style example app\")\n\n## Installation\n```bash\npip install -U torch2coreml\n```\n\nIn order to use this tool you need to have these installed:\n* Xcode 9\n* python 2.7\n\nIf you want to run tests, you need MacOS High Sierra 10.13 installed.\n\n## Dependencies\n\n* coremltools (0.6.2+)\n* PyTorch\n\n## How to use\nUsing this library you can implement converter for your own model types. An example of such a converter is located at \"example/fast-neural-style/convert-fast-neural-style.py\".\nTo implement converters you should use single function \"convert\" from torch2coreml:\n\n```python\nfrom torch2coreml import convert\n```\n\nThis function is simple enough to be self-describing:\n\n```python\ndef convert(model,\n            input_shapes,\n            input_names=['input'],\n            output_names=['output'],\n            mode=None,\n            image_input_names=[],\n            preprocessing_args={},\n            image_output_names=[],\n            deprocessing_args={},\n            class_labels=None,\n            predicted_feature_name='classLabel',\n            unknown_layer_converter_fn=None)\n```\n\n### Parameters\n__model__: Torch7 model (loaded with PyTorch) | str  \n    A trained Torch7 model loaded in python using PyTorch or path to file\n    with model (*.t7).\n\n__input_shapes__: list of tuples\n    Shapes of the input tensors.\n\n__mode__: str ('classifier', 'regressor' or None)  \n    Mode of the converted coreml model:  \n    'classifier', a NeuralNetworkClassifier spec will be constructed.  \n    'regressor', a NeuralNetworkRegressor spec will be constructed.\n\n__preprocessing_args__: dict  \n    'is_bgr', 'red_bias', 'green_bias', 'blue_bias', 'gray_bias',\n    'image_scale' keys with the same meaning as\n    https://apple.github.io/coremltools/generated/coremltools.models.neural_network.html#coremltools.models.neural_network.NeuralNetworkBuilder.set_pre_processing_parameters\n\n__deprocessing_args__: dict  \n    Same as 'preprocessing_args' but for deprocessing.\n\n__class_labels__: A string or list of strings.  \n    As a string it represents the name of the file which contains\n    the classification labels (one per line).\n    As a list of strings it represents a list of categories that map\n    the index of the output of a neural network to labels in a classifier.\n\n__predicted_feature_name__: str  \n    Name of the output feature for the class labels exposed in the Core ML\n    model (applies to classifiers only). Defaults to 'classLabel'\n\n__unknown_layer_converter_fn__: function with signature:  \n    (builder, name, layer, input_names, output_names)  \n        builder: object - instance of NeuralNetworkBuilder class  \n        name: str - generated layer name  \n        layer: object - PyTorch (python) object for corresponding layer  \n        input_names: list of strings  \n        output_names: list of strings  \n        Returns: list of strings for layer output names  \n    Callback function to handle unknown for torch2coreml layers\n\n### Returns\nmodel: A coreml model.\n\n## Currently supported\n### Models\nOnly Torch7 \"nn\" module is supported now.\n\n### Layers\nList of Torch7 layers that can be converted into their CoreML equivalent:\n\n1. Sequential\n2. ConcatTable\n3. SpatialConvolution\n4. ELU\n5. ReLU\n6. SpatialBatchNormalization\n7. Identity\n8. CAddTable\n9. SpatialFullConvolution\n10. SpatialSoftMax\n11. SpatialMaxPooling\n12. SpatialAveragePooling\n13. View\n14. Linear\n15. Tanh\n16. MulConstant\n17. SpatialZeroPadding\n18. SpatialReflectionPadding\n19. Narrow\n20. SpatialUpSamplingNearest\n21. SplitTable\n\n## License\n\nCopyright (c) 2017 Prisma Labs, Inc. All rights reserved.\n\nUse of this source code is governed by the [MIT License](https://opensource.org/licenses/MIT) that can be found in the LICENSE.txt file.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprisma-ai%2Ftorch2coreml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fprisma-ai%2Ftorch2coreml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fprisma-ai%2Ftorch2coreml/lists"}