Skip to content

Instantly share code, notes, and snippets.

@craftoid
Last active June 22, 2020 06:53
Show Gist options
  • Save craftoid/64d67f899e1014319047a37c78e30785 to your computer and use it in GitHub Desktop.
Save craftoid/64d67f899e1014319047a37c78e30785 to your computer and use it in GitHub Desktop.
IBM-MAX Image Colorizer

Image Colorizer Example Flow

screenshot

This flow uses the Image Colorizer deep learning model from the IBM Model Asset Exchange to colorize black & white images.

We are posting the original image using multipart form data. The headers, payload and url for the request can be constructed using a change or a function node respectively.

Requirements

[
{
"id": "dcdc37fc.6d748",
"type": "tab",
"label": "Image Colorizer",
"disabled": false,
"info": "This flow uses the [Image Colorizer](https://developer.ibm.com/exchanges/models/all/max-image-colorizer/) deep learning model from the IBM Model Asset Exchange to colorize black & white images.\n\nWe are posting the original image using multipart form data. The headers, payload and url for the request can be constructed using a `change` or a `function` node respectively.\n\n\n## Requirements\n\n - [node-red-contrib-image-tools](https://flows.nodered.org/node/node-red-contrib-image-tools)\n"
},
{
"id": "9e0c491f.61e638",
"type": "http request",
"z": "dcdc37fc.6d748",
"name": "",
"method": "GET",
"ret": "bin",
"paytoqs": false,
"url": "https://i.guim.co.uk/img/media/3656ae6ea2209d4561caf04fa9f172a519908ca3/0_28_2318_1391/master/2318.jpg?width=1200&height=1200&quality=85&auto=format&fit=crop&s=afcc355f47876bc495cdc3c902639bae",
"tls": "",
"persist": false,
"proxy": "",
"authType": "",
"x": 290,
"y": 120,
"wires": [
[
"8e9e2dc2.95aaf8",
"670dfe9e.c62a5",
"2253ac69.5c148c"
]
]
},
{
"id": "8e9e2dc2.95aaf8",
"type": "image viewer",
"z": "dcdc37fc.6d748",
"name": "",
"width": "400",
"data": "payload",
"dataType": "msg",
"x": 110,
"y": 260,
"wires": [
[]
]
},
{
"id": "f310d320.cb58f",
"type": "inject",
"z": "dcdc37fc.6d748",
"name": "",
"topic": "",
"payload": "",
"payloadType": "date",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 120,
"y": 120,
"wires": [
[
"9e0c491f.61e638"
]
]
},
{
"id": "1024136a.b4b4dd",
"type": "debug",
"z": "dcdc37fc.6d748",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"x": 970,
"y": 120,
"wires": []
},
{
"id": "d1e3de64.aa5248",
"type": "http request",
"z": "dcdc37fc.6d748",
"name": "",
"method": "POST",
"ret": "bin",
"paytoqs": false,
"url": "",
"tls": "",
"persist": false,
"proxy": "",
"authType": "",
"x": 730,
"y": 120,
"wires": [
[
"1024136a.b4b4dd",
"8a6df8eb.1985b"
]
]
},
{
"id": "670dfe9e.c62a5",
"type": "change",
"z": "dcdc37fc.6d748",
"d": true,
"name": "",
"rules": [
{
"t": "set",
"p": "headers",
"pt": "msg",
"to": "{\"Content-Type\":\"multipart/form-data\"}",
"tot": "json"
},
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "{\t 'image' : {\t 'value': payload,\t 'options': {\t 'filename': 'image.jpg'\t }\t }\t}",
"tot": "jsonata"
},
{
"t": "set",
"p": "api",
"pt": "msg",
"to": "http://max-image-colorizer.codait-prod-41208c73af8fca213512856c7a09db52-0000.us-east.containers.appdomain.cloud",
"tot": "str"
},
{
"t": "set",
"p": "endpoint",
"pt": "msg",
"to": "/model/predict",
"tot": "str"
},
{
"t": "set",
"p": "url",
"pt": "msg",
"to": "$join([api, endpoint])",
"tot": "jsonata"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 520,
"y": 100,
"wires": [
[
"d1e3de64.aa5248"
]
]
},
{
"id": "8a6df8eb.1985b",
"type": "image viewer",
"z": "dcdc37fc.6d748",
"name": "",
"width": "400",
"data": "payload",
"dataType": "msg",
"x": 570,
"y": 260,
"wires": [
[]
]
},
{
"id": "2253ac69.5c148c",
"type": "function",
"z": "dcdc37fc.6d748",
"name": "multipart form",
"func": "msg.headers = {\n \"Content-Type\": \"multipart/form-data\"\n};\n\nmsg.payload = {\n 'image' : {\n 'value': msg.payload,\n 'options': {\n 'filename': 'image.jpg'\n }\n }\n};\n\nlet api = \"http://max-image-colorizer.codait-prod-41208c73af8fca213512856c7a09db52-0000.us-east.containers.appdomain.cloud\";\n\nlet endpoint = \"/model/predict\";\n\nmsg.url = api + endpoint;\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"x": 520,
"y": 140,
"wires": [
[
"d1e3de64.aa5248"
]
]
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment