diff --git a/.circleci/config.yml b/.circleci/config.yml
index 5c2f4fb..0f3fa41 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -48,6 +48,28 @@ jobs:
infura-api-key: ${INFURA_API_KEY}
daemon-version: ${CI_SNETD_VERSION}
daemon-pk: ${PK_DEEPFAKES_FACESWAP}
+ deoldify-colorizer:
+ docker:
+ - image: circleci/python:3.6.6-node
+ steps:
+ - checkout
+ - ssh-deployment/deploy:
+ ssh-host: ${SSH_HOST_DEOLDIFY_COLORIZER}
+ ssh-user: ${SSH_USER_DEOLDIFY_COLORIZER}
+ service-dir: "services/deoldify-colorizer"
+ mainnet-port: "7084"
+ testnet-port: "7085"
+ run-command: "python3 run_colorize_service.py --ssl"
+ docker-test-files: "Dockerfile, requirements.txt"
+ docker-file-path: "services/deoldify-colorizer/Dockerfile"
+ docker-no-cache: true
+ docker-image: "deoldify_colorizer"
+ docker-container: "DEOLDIFY_COLORIZER"
+ docker-nvidia: true
+ docker-volumes: "-v ~/singnet/.certs:/opt/singnet/.certs"
+ infura-api-key: ${INFURA_API_KEY}
+ daemon-version: ${CI_SNETD_VERSION}
+ daemon-pk: ${PK_DEOLDIFY_COLORIZER}
i3d-video-action-recognition:
docker:
- image: circleci/python:3.6.6-node
@@ -158,28 +180,6 @@ jobs:
infura-api-key: ${INFURA_API_KEY}
daemon-version: ${CI_SNETD_VERSION}
daemon-pk: ${PK_S2VT_VIDEO_CAPTIONING}
- siggraph-colorization:
- docker:
- - image: circleci/python:3.6.6-node
- steps:
- - checkout
- - ssh-deployment/deploy:
- ssh-host: ${SSH_HOST_SIGGRAPH_COLORIZATION}
- ssh-user: ${SSH_USER_SIGGRAPH_COLORIZATION}
- service-dir: "services/siggraph-colorization"
- mainnet-port: "7084"
- testnet-port: "7085"
- run-command: "python3 run_colorize_service.py --ssl"
- docker-test-files: "Dockerfile, requirements.txt"
- docker-file-path: "services/siggraph-colorization/Dockerfile"
- docker-no-cache: true
- docker-image: "siggraph_colorization"
- docker-container: "SIGGRAPH_COLORIZATION"
- docker-nvidia: true
- docker-volumes: "-v ~/singnet/.certs:/opt/singnet/.certs"
- infura-api-key: ${INFURA_API_KEY}
- daemon-version: ${CI_SNETD_VERSION}
- daemon-pk: ${PK_SIGGRAPH_COLORIZATION}
sound-spleeter:
docker:
- image: circleci/python:3.6.6-node
@@ -256,6 +256,11 @@ jobs:
ssh-user: ${SSH_USER_CNTK_IMAGE_RECON}
test-command: "sleep 10;source '/cntk/activate-cntk';python3 test_image_recon_service.py auto"
docker-container: "CNTK_IMAGE_RECON"
+ - ssh-deployment/test:
+ ssh-host: ${SSH_HOST_DEOLDIFY_COLORIZER}
+ ssh-user: ${SSH_USER_DEOLDIFY_COLORIZER}
+ test-command: "sleep 10;python3 test_colorize_service.py auto"
+ docker-container: "DEOLDIFY_COLORIZER"
- ssh-deployment/test:
ssh-host: ${SSH_HOST_I3D_VIDEO_ACTION_RECON}
ssh-user: ${SSH_USER_I3D_VIDEO_ACTION_RECON}
@@ -302,18 +307,19 @@ workflows:
jobs:
- cntk-image-recon
# - deepfakes-faceswap
+ - deoldify-colorizer
- i3d-video-action-recognition
- places365-scene-recognition
- pneumonia-diagnosis
- real-time-voice-cloning
- s2vt-video-captioning
-# - siggraph-colorization
- sound-spleeter
- yolov3-object-detection
- zeta36-chess-alpha-zero
- testing:
requires:
- cntk-image-recon
+ - deoldify-colorizer
- i3d-video-action-recognition
- places365-scene-recognition
- pneumonia-diagnosis
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..3c0ace6
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "services/deoldify-colorizer/DeOldify"]
+ path = services/deoldify-colorizer/DeOldify
+ url = https://github.com/jantic/DeOldify
diff --git a/README.md b/README.md
index 71f1d89..74af93c 100644
--- a/README.md
+++ b/README.md
@@ -34,17 +34,7 @@ For more details on how to publish and test a service, select it from the list b
### Images:
- [cntk-image-recon](services/cntk-image-recon) ([User's Guide](docs/users_guide/cntk-image-recon.md)) - This service uses ResNet152 model, trained to recognize different types of flowers and dog breeds. [[Reference](https://cntk.ai/pythondocs/CNTK_301_Image_Recognition_with_Deep_Transfer_Learning.html)]
- [deepfakes-faceswap](services/deepfakes-faceswap) ([User's Guide](docs/users_guide/deepfakes-faceswap.md)) - This service uses the Deepfakes Faceswap, trained on two input videos A and B, to perform face swapping on videos. [[Reference](https://github.com/deepfakes/faceswap)]
-- [siggraph-colorization](services/siggraph-colorization) ([User's Guide](docs/users_guide/siggraph-colorization.md)) - This service learns to automatically color grayscale images with a deep network. [[Reference](http://iizuka.cs.tsukuba.ac.jp/projects/colorization/en/)]
- ```
- @Article{IizukaSIGGRAPH2016,
- author = {Satoshi Iizuka and Edgar Simo-Serra and Hiroshi Ishikawa},
- title = {{Let there be Color!: Joint End-to-end Learning of Global and Local Image Priors for Automatic Image Colorization with Simultaneous Classification}},
- journal = "ACM Transactions on Graphics (Proc. of SIGGRAPH 2016)",
- year = 2016,
- volume = 35,
- number = 4,
- }
- ```
+- [deoldify-colorizer](services/deoldify-colorizer) ([User's Guide](docs/users_guide/deoldify-colorizer.md)) - This service colorizes grayscale images using an AI model. [[Reference](https://github.com/jantic/DeOldify)]
- [yolov3-object-detection](services/yolov3-object-detection) ([User's Guide](docs/users_guide/yolov3-object-detection.md)) - This service uses YOLOv3 model to detect objects on images. [[Reference](https://pjreddie.com/darknet/yolo/)]
```
@article{yolov3,
@@ -101,6 +91,7 @@ Each service is licensed as followed:
- cntk-image-recon - [MIT License](https://github.com/Microsoft/CNTK/blob/master/LICENSE.md)
- deepfakes-faceswap - [GPL-3.0](https://github.com/deepfakes/faceswap/blob/master/LICENSE)
+- deoldify-colorizer - [MIT License](https://github.com/jantic/DeOldify/blob/master/LICENSE)
- i3d-video-action-recognition - [Apache License 2.0](https://github.com/deepmind/kinetics-i3d/blob/master/LICENSE)
- places365-scene-recognition - [MIT License](https://github.com/CSAILVision/places365/blob/master/LICENSE)
- pneumonia-diagnosis - [Attribution 4.0 International (CC BY 4.0)](https://creativecommons.org/licenses/by/4.0/)
diff --git a/docs/assets/users_guide/carnaval_colorized.png b/docs/assets/users_guide/carnaval_colorized.png
index 8bb43b7..4652eb2 100644
Binary files a/docs/assets/users_guide/carnaval_colorized.png and b/docs/assets/users_guide/carnaval_colorized.png differ
diff --git a/docs/assets/users_guide/jucelino_colorized.png b/docs/assets/users_guide/jucelino_colorized.png
index 13b5f35..9c1c535 100644
Binary files a/docs/assets/users_guide/jucelino_colorized.png and b/docs/assets/users_guide/jucelino_colorized.png differ
diff --git a/docs/assets/users_guide/jucelino_colorized_10.png b/docs/assets/users_guide/jucelino_colorized_10.png
new file mode 100644
index 0000000..f938b1b
Binary files /dev/null and b/docs/assets/users_guide/jucelino_colorized_10.png differ
diff --git a/docs/index.html b/docs/index.html
index 4f95938..7befe5d 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -190,21 +190,21 @@
Free
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -55,7 +55,7 @@
siggraph-colorization
this.update = function () {
var rawFile = new XMLHttpRequest();
var allText = "# Fail!";
- rawFile.open("GET", "siggraph-colorization.md", false);
+ rawFile.open("GET", "deoldify-colorizer.md", false);
rawFile.onreadystatechange = function ()
{
if(rawFile.readyState === 4)
diff --git a/docs/users_guide/siggraph-colorization.md b/docs/users_guide/deoldify-colorizer.md
similarity index 69%
rename from docs/users_guide/siggraph-colorization.md
rename to docs/users_guide/deoldify-colorizer.md
index 09ac754..1c31d86 100644
--- a/docs/users_guide/siggraph-colorization.md
+++ b/docs/users_guide/deoldify-colorizer.md
@@ -3,9 +3,9 @@

-# Let there be Color!
+# DeOldify
-This service uses [Let there be Color!](http://iizuka.cs.tsukuba.ac.jp/projects/colorization/en/) to perform colorization on grayscale images.
+This service uses [DeOldify](https://github.com/jantic/DeOldify) to perform automatic image colorization.
It is part of our third party [DNN Model Services](https://github.com/singnet/dnn-model-services).
@@ -13,7 +13,7 @@ It is part of our third party [DNN Model Services](https://github.com/singnet/dn
The service receives a grayscale image and uses it as an input for a pre-trained Torch model.
-The model was trained on the [Places dataset](http://places.csail.mit.edu/) and thus best performance is for natural outdoor images.
+The model was trained on the [ImageNet](http://www.image-net.org/download-images).
### What’s the point?
@@ -25,6 +25,7 @@ The user must provide the following input in order to start the service and get
Input:
- `img_input`: A grayscale image URL.
+ - `render_factor`: An integer factor between 7 and 45 (`default: 35`).
You can use this service from [SingularityNET DApp](http://beta.singularitynet.io/).
@@ -33,7 +34,7 @@ You can also call the service from SingularityNET CLI (`snet`).
Assuming that you have an open channel to this service:
```
-$ snet client call snet siggraph-colorization default_group colorize '{"img_input": "https://snet-models.s3.amazonaws.com/bh/Colorize/carnaval.jpg"}'
+$ snet client call snet deoldify-colorizer default_group colorize '{"img_input": "https://snet-models.s3.amazonaws.com/bh/Colorize/carnaval.jpg"}'
[Base64 Image]
```
@@ -54,8 +55,11 @@ Input Image:

-
Response:

+Response (using `render_factor: 10`):
+
+
+
diff --git a/services/deoldify-colorizer/DeOldify b/services/deoldify-colorizer/DeOldify
new file mode 160000
index 0000000..3dde8a7
--- /dev/null
+++ b/services/deoldify-colorizer/DeOldify
@@ -0,0 +1 @@
+Subproject commit 3dde8a7fdc243d87f756d4f4e7c38f6761ea807a
diff --git a/services/deoldify-colorizer/Dockerfile b/services/deoldify-colorizer/Dockerfile
new file mode 100644
index 0000000..fd75244
--- /dev/null
+++ b/services/deoldify-colorizer/Dockerfile
@@ -0,0 +1,51 @@
+FROM pytorch/pytorch:1.4-cuda10.1-cudnn7-runtime
+
+ARG git_owner="singnet"
+ARG git_repo="dnn-model-services"
+ARG git_branch="master"
+ARG snetd_version
+
+ENV SINGNET_REPOS=/opt/singnet
+ENV DNN_REPO_NAME=${git_repo}
+ENV SERVICES_FOLDER=${SINGNET_REPOS}/${DNN_REPO_NAME}/services
+ENV SERVICE_NAME=deoldify-colorizer
+
+RUN mkdir -p ${SINGNET_REPOS}
+
+RUN apt-get update && \
+ apt-get install -y \
+ git \
+ wget \
+ nano \
+ curl
+
+# OpenCV dependencies
+RUN apt-get install -y libglib2.0-0 libsm6 libxext6 libxrender-dev
+
+# Installing SNET Daemon
+RUN SNETD_GIT_VERSION=`curl -s https://api.github.com/repos/singnet/snet-daemon/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")' || echo "v3.1.3"` && \
+ SNETD_VERSION=${snetd_version:-${SNETD_GIT_VERSION}} && \
+ cd /tmp && \
+ wget https://github.com/singnet/snet-daemon/releases/download/${SNETD_VERSION}/snet-daemon-${SNETD_VERSION}-linux-amd64.tar.gz && \
+ tar -xvf snet-daemon-${SNETD_VERSION}-linux-amd64.tar.gz && \
+ mv snet-daemon-${SNETD_VERSION}-linux-amd64/snetd /usr/bin/snetd
+
+# Cloning service repository, downloading models
+RUN cd ${SINGNET_REPOS} && \
+ git clone -b ${git_branch} https://github.com/${git_owner}/${DNN_REPO_NAME}.git && \
+ cd ${DNN_REPO_NAME}/utils && \
+ ./get_colorize_model.sh
+
+# DeOldify Repository
+RUN cd ${SINGNET_DIR}/${SERVICE_NAME} && \
+ git submodule update --init -- DeOldify && \
+ cd DeOldify && \
+ pip install -r requirements.txt
+
+# Building protobuf messages
+RUN cd ${SERVICES_FOLDER}/${SERVICE_NAME} && \
+ pip install -U pip && \
+ pip install -r requirements.txt && \
+ sh buildproto.sh
+
+WORKDIR ${SERVICES_FOLDER}/${SERVICE_NAME}
\ No newline at end of file
diff --git a/services/siggraph-colorization/README.md b/services/deoldify-colorizer/README.md
similarity index 82%
rename from services/siggraph-colorization/README.md
rename to services/deoldify-colorizer/README.md
index c879756..d8410b3 100644
--- a/services/siggraph-colorization/README.md
+++ b/services/deoldify-colorizer/README.md
@@ -3,10 +3,9 @@

-# Let there be Color!
+# DeOldify
-This service uses [siggraph2016_colorization](http://iizuka.cs.tsukuba.ac.jp/projects/colorization/en/) to perform
-automatic image colorization with simultaneous classification.
+This service uses [DeOldify](https://github.com/jantic/DeOldify) to perform automatic image colorization.
It is part of our third party [DNN Model Services](https://github.com/singnet/dnn-model-services).
@@ -16,7 +15,7 @@ It is part of our third party [DNN Model Services](https://github.com/singnet/dn
- [Python 3.6.5](https://www.python.org/downloads/release/python-365/)
- [SNET CLI](https://github.com/singnet/snet-cli)
-- Pre-trained model (`colornet.t7`)
+- Pre-trained model (`ColorizeArtistic_gen.pth`)
### Development
@@ -27,11 +26,12 @@ $ git clone https://github.com/singnet/dnn-model-services.git
$ cd dnn-model-services/utils
$ ./get_colorize_model.sh
$ ls -la Resources/Models
-total 678421
-drwxrwxr-x 2 user user 4096 Apr 25 08:49 .
-drwxrwxr-x 3 user user 4096 Apr 25 08:49 ..
--rw-r--r-- 1 root root 694703608 Apr 22 2016 colornet.t7
-$ cd ../services/cntk-image-recon
+total 249188
+drwxrwxr-x 2 ci ci 4096 Mar 24 13:30 ./
+drwxrwxr-x 5 ci ci 4096 Mar 24 13:29 ../
+-rw-rw-r-- 1 ci ci 255144681 Mar 24 13:30 ColorizeArtistic_gen.pth
+-rw-rw-r-- 1 ci ci 9210 Mar 24 13:30 watermark.png
+$ cd ../services/deoldify-colorizer
```
### Running the service:
@@ -63,13 +63,13 @@ For example (using the Ropsten testnet):
```
$ cat snetd.config.json
{
- "DAEMON_END_POINT": "0.0.0.0:7054",
+ "DAEMON_END_POINT": "0.0.0.0:7085",
"IPFS_END_POINT": "http://ipfs.singularitynet.io:80",
"BLOCKCHAIN_NETWORK_SELECTED": "ropsten",
"PASSTHROUGH_ENABLED": true,
"PASSTHROUGH_ENDPOINT": "http://localhost:7003",
"ORGANIZATION_ID": "snet",
- "SERVICE_ID": "siggraph-colorization",
+ "SERVICE_ID": "deoldify-colorizer",
"LOG": {
"LEVEL": "debug",
"OUTPUT": {
@@ -115,7 +115,7 @@ Through SingularityNET (follow this [link](https://dev.singularitynet.io/tutoria
Assuming that you have an open channel to this service:
```
-$ snet client call snet siggraph-colorization default_group colorize '{"img_input": "https://snet-models.s3.amazonaws.com/bh/Colorize/carnaval.jpg"}'
+$ snet client call snet deoldify-colorizer default_group colorize '{"img_input": "https://snet-models.s3.amazonaws.com/bh/Colorize/carnaval.jpg"}'
[Base64 Image]
diff --git a/services/siggraph-colorization/buildproto.sh b/services/deoldify-colorizer/buildproto.sh
similarity index 100%
rename from services/siggraph-colorization/buildproto.sh
rename to services/deoldify-colorizer/buildproto.sh
diff --git a/services/siggraph-colorization/requirements.txt b/services/deoldify-colorizer/requirements.txt
similarity index 100%
rename from services/siggraph-colorization/requirements.txt
rename to services/deoldify-colorizer/requirements.txt
diff --git a/services/siggraph-colorization/run_colorize_service.py b/services/deoldify-colorizer/run_colorize_service.py
similarity index 97%
rename from services/siggraph-colorization/run_colorize_service.py
rename to services/deoldify-colorizer/run_colorize_service.py
index cefbe48..b209c0d 100644
--- a/services/siggraph-colorization/run_colorize_service.py
+++ b/services/deoldify-colorizer/run_colorize_service.py
@@ -12,7 +12,7 @@
from service import registry
logging.basicConfig(level=10, format="%(asctime)s - [%(levelname)8s] - %(name)s - %(message)s")
-log = logging.getLogger("run_siggraph_colorization_service")
+log = logging.getLogger("run_colorization_service")
def main():
@@ -23,7 +23,7 @@ def main():
root_path = pathlib.Path(__file__).absolute().parent
# All services modules go here
- service_modules = ["service.siggraph_colorization_service"]
+ service_modules = ["service.colorization_service"]
# Call for all the services listed in service_modules
all_p = start_all_services(root_path, service_modules, args.run_daemon, args.run_ssl)
diff --git a/services/deoldify-colorizer/service/__init__.py b/services/deoldify-colorizer/service/__init__.py
new file mode 100644
index 0000000..ac15312
--- /dev/null
+++ b/services/deoldify-colorizer/service/__init__.py
@@ -0,0 +1,5 @@
+registry = {
+ "colorization_service": {
+ "grpc": 7003,
+ },
+}
\ No newline at end of file
diff --git a/services/siggraph-colorization/service/siggraph_colorization.py b/services/deoldify-colorizer/service/colorization.py
similarity index 65%
rename from services/siggraph-colorization/service/siggraph_colorization.py
rename to services/deoldify-colorizer/service/colorization.py
index 1251e7b..5c4922a 100644
--- a/services/siggraph-colorization/service/siggraph_colorization.py
+++ b/services/deoldify-colorizer/service/colorization.py
@@ -1,34 +1,27 @@
import os
+import sys
import requests
import hashlib
import datetime
-import subprocess
import base64
+from pathlib import Path
import logging
import traceback
+SERVICE_FOLDER = Path(__file__).absolute().parent.parent.joinpath("DeOldify")
+sys.path.insert(0, str(SERVICE_FOLDER))
+from deoldify.visualize import get_artistic_image_colorizer
+
+
logging.basicConfig(level=10, format="%(asctime)s - [%(levelname)8s] - %(name)s - %(message)s")
-log = logging.getLogger("siggraph_colorization")
+log = logging.getLogger("colorization")
class Colorization:
- def __init__(self, img_input):
+ def __init__(self, img_input, render_factor=35):
self.img_input = img_input
+ self.render_factor = render_factor
self.response = dict()
-
- @staticmethod
- def _is_base64(sb):
- try:
- if type(sb) == str:
- sb_bytes = bytes(sb, 'ascii')
- elif type(sb) == bytes:
- sb_bytes = sb
- else:
- raise ValueError("Argument must be string or bytes")
- return base64.b64encode(base64.b64decode(sb_bytes)) == sb_bytes
- except Exception as e:
- log.error("Not Base64: " + str(e))
- return False
@staticmethod
def _generate_uid():
@@ -41,12 +34,10 @@ def _generate_uid():
return m[:10] + m[-10:]
def colorize(self):
-
try:
uid = self._generate_uid()
input_file = uid + "_input.png"
- output_img = uid + ".png"
-
+
# Link
if "http://" in self.img_input or "https://" in self.img_input:
log.info("Got an URL, downloading...")
@@ -55,7 +46,7 @@ def colorize(self):
with open(input_file, "wb") as fd:
fd.write(r.content)
log.info("Done!")
-
+
# Base64
elif len(self.img_input) > 1000:
log.info("Got a base64 image data, saving...")
@@ -63,14 +54,17 @@ def colorize(self):
fd.write(base64.b64decode(self.img_input))
log.info("Done!")
- resources_root = os.path.join("..", "..", "utils", "Resources")
- colorize_model = os.path.join(resources_root, "Models", "colornet.t7")
- p = subprocess.Popen(["th",
- "colorize.lua",
- input_file,
- output_img,
- colorize_model])
- p.wait()
+ # from DeOldify
+ if not os.path.exists("test_images"):
+ os.makedirs("test_images")
+
+ resources_root = Path().absolute().parent.parent.joinpath("utils", "Resources", "Models", "DeOldify")
+ colorizer = get_artistic_image_colorizer(root_folder=resources_root,
+ weights_name="ColorizeArtistic_gen",
+ results_dir="/tmp/")
+ output_img = colorizer.plot_transformed_image(path=input_file,
+ render_factor=self.render_factor,
+ watermarked=resources_root.joinpath("watermark.png"))
self.response["img_colorized"] = "Fail"
with open(output_img, "rb") as base64_file:
diff --git a/services/siggraph-colorization/service/siggraph_colorization_service.py b/services/deoldify-colorizer/service/colorization_service.py
similarity index 68%
rename from services/siggraph-colorization/service/siggraph_colorization_service.py
rename to services/deoldify-colorizer/service/colorization_service.py
index 9c23f68..d6c034f 100644
--- a/services/siggraph-colorization/service/siggraph_colorization_service.py
+++ b/services/deoldify-colorizer/service/colorization_service.py
@@ -5,15 +5,21 @@
import grpc
import concurrent.futures as futures
+import multiprocessing
+
import service.common
-from service.siggraph_colorization import Colorization
+from service.colorization import Colorization
# Importing the generated codes from buildproto.sh
import service.service_spec.colorization_pb2_grpc as grpc_bt_grpc
from service.service_spec.colorization_pb2 import Output
logging.basicConfig(level=10, format="%(asctime)s - [%(levelname)8s] - %(name)s - %(message)s")
-log = logging.getLogger("siggraph_colorization_service")
+log = logging.getLogger("colorization_service")
+
+
+def mp_colorize(obj, return_dict):
+ return_dict["response"] = obj.colorize()
# Create a class to be added to the gRPC server
@@ -26,16 +32,22 @@ def __init__(self):
# The method that will be exposed to the snet-cli call command.
# request: incoming data
# context: object that provides RPC-specific information (timeout, etc).
- def colorize(self, request, context):
+ def colorize(self, request, _):
try:
- sig_colorize = Colorization(request.img_input)
- tmp_response = sig_colorize.colorize()
+ obj = Colorization(request.img_input, request.render_factor)
- # To respond we need to fill this "img_colorized" field of Output() object (from .proto file)
- self.response.img_colorized = tmp_response["img_colorized"]
+ manager = multiprocessing.Manager()
+ return_dict = manager.dict()
+ p = multiprocessing.Process(target=mp_colorize, args=(obj, return_dict))
+ p.start()
+ p.join()
- log.debug("translate({})={}".format(request.img_input[:50], self.response.img_colorized[:50]))
- return self.response
+ response = return_dict.get("response", None)
+ if not response:
+ return Output()
+
+ log.debug("colorize({})={}".format(request.img_input[:50], response["img_colorized"][:50]))
+ return Output(img_colorized=response["img_colorized"])
except Exception as e:
traceback.print_exc()
diff --git a/services/siggraph-colorization/service/common.py b/services/deoldify-colorizer/service/common.py
similarity index 100%
rename from services/siggraph-colorization/service/common.py
rename to services/deoldify-colorizer/service/common.py
diff --git a/services/siggraph-colorization/service/service_spec/colorization.proto b/services/deoldify-colorizer/service/service_spec/colorization.proto
similarity index 86%
rename from services/siggraph-colorization/service/service_spec/colorization.proto
rename to services/deoldify-colorizer/service/service_spec/colorization.proto
index b552129..718f1fc 100644
--- a/services/siggraph-colorization/service/service_spec/colorization.proto
+++ b/services/deoldify-colorizer/service/service_spec/colorization.proto
@@ -2,6 +2,7 @@ syntax = "proto3";
message Input {
string img_input = 1;
+ int32 render_factor = 2;
}
message Output {
diff --git a/services/siggraph-colorization/snetd_configs/snetd.mainnet.json b/services/deoldify-colorizer/snetd_configs/snetd.mainnet
similarity index 92%
rename from services/siggraph-colorization/snetd_configs/snetd.mainnet.json
rename to services/deoldify-colorizer/snetd_configs/snetd.mainnet
index 8718a78..cf9c1c1 100644
--- a/services/siggraph-colorization/snetd_configs/snetd.mainnet.json
+++ b/services/deoldify-colorizer/snetd_configs/snetd.mainnet
@@ -5,7 +5,7 @@
"passthrough_endpoint": "http://localhost:7003",
"blockchain_network_selected": "main",
"organization_id": "snet",
- "service_id": "siggraph-colorization",
+ "service_id": "deoldify-colorizer",
"log": {
"level": "debug",
"output": {
diff --git a/services/siggraph-colorization/snetd_configs/snetd.ropsten b/services/deoldify-colorizer/snetd_configs/snetd.ropsten.json
similarity index 92%
rename from services/siggraph-colorization/snetd_configs/snetd.ropsten
rename to services/deoldify-colorizer/snetd_configs/snetd.ropsten.json
index 9e3edfa..06a1e46 100644
--- a/services/siggraph-colorization/snetd_configs/snetd.ropsten
+++ b/services/deoldify-colorizer/snetd_configs/snetd.ropsten.json
@@ -5,7 +5,7 @@
"passthrough_endpoint": "http://localhost:7003",
"blockchain_network_selected": "ropsten",
"organization_id": "snet",
- "service_id": "siggraph-colorization",
+ "service_id": "deoldify-colorizer",
"log": {
"level": "debug",
"output": {
diff --git a/services/siggraph-colorization/test_colorize_service.py b/services/deoldify-colorizer/test_colorize_service.py
similarity index 83%
rename from services/siggraph-colorization/test_colorize_service.py
rename to services/deoldify-colorizer/test_colorize_service.py
index 479a4ef..5a26062 100644
--- a/services/siggraph-colorization/test_colorize_service.py
+++ b/services/deoldify-colorizer/test_colorize_service.py
@@ -7,7 +7,7 @@
from service import registry
-TEST_URL = "https://snet-models.s3.amazonaws.com/bh/Colorize/jucelino.jpg"
+TEST_URL = "https://snet-models.s3.amazonaws.com/bh/Colorize/carnaval.jpg"
if __name__ == "__main__":
@@ -17,9 +17,9 @@
if sys.argv[1] == "auto":
test_flag = True
- endpoint = input("Endpoint (localhost:{}): ".format(registry["siggraph_colorization_service"]["grpc"])) if not test_flag else ""
+ endpoint = input("Endpoint (localhost:{}): ".format(registry["colorization_service"]["grpc"])) if not test_flag else ""
if endpoint == "":
- endpoint = "localhost:{}".format(registry["siggraph_colorization_service"]["grpc"])
+ endpoint = "localhost:{}".format(registry["colorization_service"]["grpc"])
# open a gRPC channel
channel = grpc.insecure_channel("{}".format(endpoint))
@@ -36,7 +36,6 @@
if grpc_method == "colorize":
response = stub.colorize(grpc_input)
print(response.img_colorized)
-
if response.img_colorized == "Fail":
exit(1)
else:
diff --git a/services/siggraph-colorization/Dockerfile b/services/siggraph-colorization/Dockerfile
deleted file mode 100644
index 3f16fe9..0000000
--- a/services/siggraph-colorization/Dockerfile
+++ /dev/null
@@ -1,66 +0,0 @@
-# Using this image because it performs better than nvidia/cuda-cudnn
-FROM opennmt/opennmt:latest
-
-ARG git_owner="singnet"
-ARG git_repo="dnn-model-services"
-ARG git_branch="master"
-ARG snetd_version
-
-ENV SINGNET_REPOS=/opt/singnet
-ENV DNN_REPO_NAME=${git_repo}
-ENV SERVICES_FOLDER=${SINGNET_REPOS}/${DNN_REPO_NAME}/services
-ENV SERVICE_NAME=siggraph-colorization
-
-RUN mkdir -p ${SINGNET_REPOS}
-
-RUN apt update && \
- apt install -y --no-install-recommends \
- libgomp1 \
- libprotobuf9v5 \
- libzmq1 \
- cmake \
- make \
- g++ \
- gcc \
- curl \
- nano \
- wget \
- git \
- libpng-dev \
- libjpeg-dev \
- python3-pip \
- python3 && \
- apt clean && \
- rm -rf /var/lib/apt/lists/*
-
-ENV TORCH_DIR=/root/torch
-
-ENV LUA_PATH="${TORCH_DIR}/share/lua/5.1/?.lua;${TORCH_DIR}/share/lua/5.1/?/init.lua;./?.lua"
-ENV LUA_CPATH="${TORCH_DIR}/lib/lua/5.1/?.so;./?.so;${TORCH_DIR}/lib/?.so"
-ENV PATH=${TORCH_DIR}/bin:${PATH}
-ENV LD_LIBRARY_PATH=${TORCH_DIR}/lib:${LD_LIBRARY_PATH}
-ENV THC_CACHING_ALLOCATOR=0
-
-RUN mkdir /root/mkl && \
- ln -s /root/torch/lib /root/mkl/ && \
- luarocks install image
-
-# Installing SNET Daemon
-RUN SNETD_GIT_VERSION=`curl -s https://api.github.com/repos/singnet/snet-daemon/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")' || echo "v2.0.2"` && \
- SNETD_VERSION=${snetd_version:-${SNETD_GIT_VERSION}} && \
- cd /tmp && \
- wget https://github.com/singnet/snet-daemon/releases/download/${SNETD_VERSION}/snet-daemon-${SNETD_VERSION}-linux-amd64.tar.gz && \
- tar -xvf snet-daemon-${SNETD_VERSION}-linux-amd64.tar.gz && \
- mv snet-daemon-${SNETD_VERSION}-linux-amd64/snetd /usr/bin/snetd
-
-RUN cd ${SINGNET_REPOS} && \
- git clone -b ${git_branch} https://github.com/${git_owner}/${DNN_REPO_NAME}.git && \
- cd ${DNN_REPO_NAME}/utils && \
- sh get_colorize_model.sh
-
-RUN cd ${SERVICES_FOLDER}/${SERVICE_NAME} && \
- pip3 install -U pip && \
- pip3 install -r requirements.txt && \
- sh buildproto.sh
-
-WORKDIR ${SERVICES_FOLDER}/${SERVICE_NAME}
diff --git a/services/siggraph-colorization/colorize.lua b/services/siggraph-colorization/colorize.lua
deleted file mode 100644
index 2057154..0000000
--- a/services/siggraph-colorization/colorize.lua
+++ /dev/null
@@ -1,48 +0,0 @@
---[[
- Copyright (C) <2016>
-
- This work is licensed under the Creative Commons
- Attribution-NonCommercial-ShareAlike 4.0 International License. To view a copy
- of this license, visit http://creativecommons.org/licenses/by-nc-sa/4.0/ or
- send a letter to Creative Commons, PO Box 1866, Mountain View, CA 94042, USA.
-
- Satoshi Iizuka, Waseda University
- iizuka@aoni.waseda.jp, http://hi.cs.waseda.ac.jp/~iizuka/
- Edgar Simo-Serra, Waseda University
- esimo@aoni.waseda.jp, http://hi.cs.waseda.ac.jp/~esimo/
---]]
-
-
-require 'nn'
-require 'nngraph'
-require 'image'
-
-local infile = arg[1]
-local outfile = arg[2] or 'out.png'
-local netfile = arg[3] or 'colornet.t7'
-
-local d = torch.load( netfile )
-local datamean = d.mean
-local model = d.model:float()
-
-local function pred2rgb( x, data )
- local I = torch.cat( data[1][{{1},{},{}}]:float(),
- data[1]:clone():float():mul(2):add(-1), 1)
- local O = image.scale( I, x:size(3), x:size(2) )
- local X = image.rgb2lab( image.yuv2rgb( torch.repeatTensor( x, 3, 1, 1 ) ) )
- O = O*100
- O[1] = X[1]
- O = image.rgb2yuv( image.lab2rgb( O ) )
- return image.yuv2rgb( torch.cat( x, O[{{2,3},{},{}}], 1 ) )
-end
-
-local I = image.load( infile )
-if I:size(1)==3 then I = image.rgb2y(I) end
-local X2 = image.scale( I, torch.round(I:size(3)/8)*8, torch.round(I:size(2)/8)*8 ):add(-datamean):float()
-local X1 = image.scale( X2, 224, 224 ):float()
-X1 = X1:reshape( 1, X1:size(1), X1:size(2), X1:size(3) )
-X2 = X2:reshape( 1, X2:size(1), X2:size(2), X2:size(3) )
-model.forwardnodes[9].data.module.modules[3].nfeatures = X2:size(3)/8
-model.forwardnodes[9].data.module.modules[4].nfeatures = X2:size(4)/8
-
-image.save( outfile, pred2rgb( I:float(), model:forward( {X1, X2} ) ) )
\ No newline at end of file
diff --git a/services/siggraph-colorization/service/__init__.py b/services/siggraph-colorization/service/__init__.py
deleted file mode 100644
index c9487b4..0000000
--- a/services/siggraph-colorization/service/__init__.py
+++ /dev/null
@@ -1,5 +0,0 @@
-registry = {
- "siggraph_colorization_service": {
- "grpc": 7013,
- },
-}
\ No newline at end of file
diff --git a/utils/get_colorize_model.sh b/utils/get_colorize_model.sh
index e086999..945a47e 100755
--- a/utils/get_colorize_model.sh
+++ b/utils/get_colorize_model.sh
@@ -1,32 +1,27 @@
#!/bin/bash
-DIR="./Resources/Models"
+DIR="./Resources/Models/DeOldify/models"
if [ ! -d "$DIR" ]; then
mkdir -p ${DIR}
fi
cd ${DIR} || true
-# md5sum c88fa2bb6dc9f942a492a7dc7009b966
-# sha1sum d397faf0b63a173680824474bfeab4725c375ca2
-FILENAME="colornet.t7"
-FILEURL="http://hi.cs.waseda.ac.jp/~iizuka/data/colornet.t7"
-FILEMD5="c88fa2bb6dc9f942a492a7dc7009b966"
+MODELNAME="ColorizeArtistic_gen.pth"
+WATERMARK="watermark.png"
-echo "Downloading the colorization model (663M)..."
-wget --continue -O "${FILENAME}" -- "${FILEURL}"
-
-echo "Checking integrity (md5sum)..."
-OS=$(uname -s)
-if [ "${OS}" = "Darwin" ]; then
- CHECKSUM=$(cat < "${FILENAME}" | md5)
- else
- CHECKSUM=$(md5sum "${FILENAME}" | awk '{ print $1 }')
+FILE="${MODELNAME}"
+if [ -f "${FILE}" ]
+then
+ echo "${FILE} found, skipping.."
+else
+ wget --no-check-certificate http://54.203.198.53:7000/PreTrainedDNNModels/Image/deoldify-colorizer/${FILE}
fi
-if [ "${CHECKSUM}" != "${FILEMD5}" ]; then
- echo "Integrity check failed. File is corrupt!"
- echo "Try running this script again and if it fails remove '${FILENAME}' before trying again."
- exit 1
+FILE="${WATERMARK}"
+if [ -f "${FILE}" ]
+then
+ echo "${FILE} found, skipping.."
+else
+ wget --no-check-certificate http://54.203.198.53:7000/PreTrainedDNNModels/Image/deoldify-colorizer/${FILE}
fi
-echo -e "Download finished successfully! Time to \e[31mc\e[32mo\e[33m\e[34ml\e[35mo\e[36mr\e[37mi\e[91mz\e[92me\e[93m\e[94m!\e[m"
\ No newline at end of file