├── requirements.txt ├── input.jpg ├── all-styles.jpg ├── Video_And_Photo_Inference_With_Xcode.jpg ├── models ├── PCB.mlmodel ├── Yarn.mlmodel ├── Flowerish.mlmodel ├── OldComics.mlmodel ├── Paint.mlmodel ├── Paint2.mlmodel ├── PopArt.mlmodel ├── Sketch.mlmodel ├── TicTac.mlmodel ├── AnimalAndSky.mlmodel ├── ColorSmoke.mlmodel ├── CopperShroom.mlmodel ├── CornAndClip.mlmodel ├── GoldenMoth.mlmodel ├── PaperClips.mlmodel └── SpaceWorlf.mlmodel ├── README.md ├── .gitattributes ├── test-all-styles.py ├── LICENSE └── .gitignore /requirements.txt: -------------------------------------------------------------------------------- 1 | coremltools 2 | Pillow 3 | -------------------------------------------------------------------------------- /input.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Norod/CoreML-StyleTransfer/HEAD/input.jpg -------------------------------------------------------------------------------- /all-styles.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Norod/CoreML-StyleTransfer/HEAD/all-styles.jpg -------------------------------------------------------------------------------- /Video_And_Photo_Inference_With_Xcode.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Norod/CoreML-StyleTransfer/HEAD/Video_And_Photo_Inference_With_Xcode.jpg -------------------------------------------------------------------------------- /models/PCB.mlmodel: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:bdf2def75c9456163d508655f7ff649a7156f44cf152b0a60f6e26aac2b3be4a 3 | size 6726090 4 | -------------------------------------------------------------------------------- /models/Yarn.mlmodel: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:df3e6e65550fd860c46f766105ad44e1c11412cbfa5cb702cf404bd683cd49d3 3 | size 6726090 4 | -------------------------------------------------------------------------------- /models/Flowerish.mlmodel: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:abc96ac4b587f71d3a5d28a47dedf50e7afad328c5df03237ac3e6363640e36b 3 | size 6726090 4 | -------------------------------------------------------------------------------- /models/OldComics.mlmodel: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:5a0ceb1cd5924b7661b5c134842fa47a870a20606f3b81c0aaae47f73c36e344 3 | size 6726090 4 | -------------------------------------------------------------------------------- /models/Paint.mlmodel: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:8d70af13c1007428ef5d23bddad008463848ec8fbcea388ac6002664b1980b2b 3 | size 6726090 4 | -------------------------------------------------------------------------------- /models/Paint2.mlmodel: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:c82b20adcd54822c1f7ed2c4ec05c63f20bd5abd3638d8cad39200eac9ea1e83 3 | size 6726090 4 | -------------------------------------------------------------------------------- /models/PopArt.mlmodel: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:e2cbfce77955be4a24a169f9141ddb58c5f026feff57e1329cab1c188a2e9421 3 | size 6726090 4 | -------------------------------------------------------------------------------- /models/Sketch.mlmodel: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:0178bfd5362ef78a23f6757db06143365325905cdcaaf8bd99a080df0816c72c 3 | size 6726090 4 | -------------------------------------------------------------------------------- /models/TicTac.mlmodel: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:59f35a693abe3763a0641a4f12c999c1d867c4ccd96de37e65f9f8c15768e09b 3 | size 6726090 4 | -------------------------------------------------------------------------------- /models/AnimalAndSky.mlmodel: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:cb455a66a660574a35471af4ccb1f2444cbae7bae82eb344181c2b7d89eb1dcc 3 | size 6726090 4 | -------------------------------------------------------------------------------- /models/ColorSmoke.mlmodel: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:2d443d7bf629ea821d7d2e2943041f4e242f6a731c1a5b3f09d03207ed3056e3 3 | size 6726090 4 | -------------------------------------------------------------------------------- /models/CopperShroom.mlmodel: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:637f39d1fab61e1c190980d443807d70cc0d0161777d27c2d49fbffaf6139f8e 3 | size 6726090 4 | -------------------------------------------------------------------------------- /models/CornAndClip.mlmodel: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:6c94a34fc243482257c36aabc5e1bada8d4ce8c3c5c7f71a12c1fcb64a572388 3 | size 6726090 4 | -------------------------------------------------------------------------------- /models/GoldenMoth.mlmodel: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:1746d5d520c45dfa5d989e84c52df379526b353a7d4b37ef5c485998dc705b30 3 | size 6726090 4 | -------------------------------------------------------------------------------- /models/PaperClips.mlmodel: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:b12986803297b560d6b91ac3bfbbc28850f0472280ca24890ada29091f80ebf4 3 | size 6726090 4 | -------------------------------------------------------------------------------- /models/SpaceWorlf.mlmodel: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:6772548e27ae7c466cb55dc5e13538b4cfe543143c0fd0de375a86ee01b8383e 3 | size 6726090 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CoreML-StyleTransfer 2 | 3 | A few stylization coreML models that I've trained with [CreateML](https://developer.apple.com/machine-learning/create-ml/) 4 | 5 | You can open and use the .mlmodel files in the "models" folder in Xcode: 6 | 7 | ![Video and photo inference with Xcode](Video_And_Photo_Inference_With_Xcode.jpg) 8 | 9 | You can also use test-all-styles.py as reference for inference using Python. 10 | 11 | Here are inference examples for all the styles in this repository: 12 | 13 | ![All styles](all-styles.jpg) 14 | 15 | If you end up using these styles in your own projects, I'd be glad if you let me know :) -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | models/CopperShroom.mlmodel filter=lfs diff=lfs merge=lfs -text 2 | models/CornAndClip.mlmodel filter=lfs diff=lfs merge=lfs -text 3 | models/PCB.mlmodel filter=lfs diff=lfs merge=lfs -text 4 | models/PopArt.mlmodel filter=lfs diff=lfs merge=lfs -text 5 | models/ColorSmoke.mlmodel filter=lfs diff=lfs merge=lfs -text 6 | models/GoldenMoth.mlmodel filter=lfs diff=lfs merge=lfs -text 7 | models/OldComics.mlmodel filter=lfs diff=lfs merge=lfs -text 8 | models/Paint.mlmodel filter=lfs diff=lfs merge=lfs -text 9 | models/SpaceWorlf.mlmodel filter=lfs diff=lfs merge=lfs -text 10 | models/Yarn.mlmodel filter=lfs diff=lfs merge=lfs -text 11 | models/AnimalAndSky.mlmodel filter=lfs diff=lfs merge=lfs -text 12 | models/Paint2.mlmodel filter=lfs diff=lfs merge=lfs -text 13 | models/PaperClips.mlmodel filter=lfs diff=lfs merge=lfs -text 14 | models/Sketch.mlmodel filter=lfs diff=lfs merge=lfs -text 15 | models/TicTac.mlmodel filter=lfs diff=lfs merge=lfs -text 16 | models/Flowerish.mlmodel filter=lfs diff=lfs merge=lfs -text 17 | -------------------------------------------------------------------------------- /test-all-styles.py: -------------------------------------------------------------------------------- 1 | import coremltools 2 | from PIL import Image 3 | import glob 4 | import os 5 | 6 | inputImage = Image.open('input.jpg') 7 | output_folder = './results' 8 | if os.path.exists(output_folder) == False: 9 | os.mkdir(output_folder) 10 | 11 | models_folder= "./models" 12 | model_paths = glob.glob(os.path.join(models_folder, "*.mlmodel")) 13 | for model_path in model_paths: 14 | modelname_w_ext = os.path.basename(model_path) 15 | model_name, model_extension = os.path.splitext(modelname_w_ext) 16 | print("Loading \"" + model_name + "\"") 17 | model = coremltools.models.MLModel(model_path) 18 | resized_image = inputImage.resize((512, 512)) 19 | pred = model.predict({'image': resized_image}) 20 | result = pred['stylizedImage'] 21 | result = result.resize((inputImage.width, inputImage.height)).convert('RGB') 22 | result_file = model_name + '_stylized.jpg' 23 | result_path = os.path.join(output_folder, result_file) 24 | result.save(result_path) 25 | print("Saved result to " + result_path) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Doron Adler 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | results 131 | --------------------------------------------------------------------------------