diff --git a/.circleci/config.yml b/.circleci/config.yml index 95a656e..e302088 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -321,6 +321,41 @@ jobs: docker_etcd_host_folder: singnet/etcd/${SERVICE_NAME}/ docker_etcd_container_folder: opt/singnet/${CIRCLE_PROJECT_REPONAME}/${SERVICE_FOLDER}/etcd/ + build-siggraph-colorization: + docker: + - image: circleci/python:3.6.6-node + working_directory: ~/singnet + environment: + SERVICE_NAME: siggraph-colorization + SERVICE_FOLDER: services/siggraph-colorization + SERVICE_RUN_COMMAND: bash -c "git pull;python3 run_colorize_service.py" + SERVICE_TEST_COMMAND: bash -c "sleep 10;python3 test_colorize_service.py auto" + steps: + - build_command: + docker_nvidia: true + docker_image_name: siggraph_colorization + docker_container_name: SIGGRAPH_COLORIZATION + + deploy-siggraph-colorization: + docker: + - image: circleci/python:3.6.6-node + working_directory: ~/singnet + environment: + SERVICE_NAME: siggraph-colorization + SERVICE_FOLDER: services/siggraph-colorization + CERTS_FOLDER: singnet/.certs + SERVICE_RUN_COMMAND: bash -c "git pull;python3 run_colorize_service.py --ssl" + SERVICE_TEST_COMMAND: bash -c "sleep 10;python3 test_colorize_service.py auto" + SNETD_PORT_MAINNET: 7035 + SNETD_PORT_ROPSTEN: 7085 + steps: + - deploy_command: + docker_nvidia: true + docker_image_name: siggraph_colorization + docker_container_name: SIGGRAPH_COLORIZATION + docker_etcd_host_folder: singnet/etcd/${SERVICE_NAME}/ + docker_etcd_container_folder: opt/singnet/${CIRCLE_PROJECT_REPONAME}/${SERVICE_FOLDER}/etcd/ + build-yolov3-object-detection: docker: - image: circleci/python:3.6.6-node @@ -454,6 +489,14 @@ workflows: branches: only: master + - build-siggraph-colorization + - deploy-siggraph-colorization: + requires: + - build-siggraph-colorization + filters: + branches: + only: master + - build-yolov3-object-detection - deploy-yolov3-object-detection: requires: diff --git a/.gitignore b/.gitignore index 35c42c0..b32059b 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,5 @@ config/ !/services/ **/etcd/ !/docs/assets/*.jpg -!/docs/assets/users_guide/*.jpg \ No newline at end of file +!/docs/assets/users_guide/*.jpg +!/docs/assets/users_guide/*.png \ No newline at end of file diff --git a/README.md b/README.md index ada1da2..8897811 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,17 @@ 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)] +- [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. + ``` + @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, + } + ``` - [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, @@ -74,5 +85,6 @@ Each service is licensed as followed: - 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) - s2vt-video-captioning - [Attribution 4.0 International (CC BY 4.0)](http://creativecommons.org/licenses/by/4.0/) +- siggraph-colorization - [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License](https://github.com/satoshiiizuka/siggraph2016_colorization/blob/master/LICENSE) - yolov3-object-detection - [Public domain](https://github.com/pjreddie/darknet/blob/master/LICENSE) - zeta36-chess-alpha-zero - [MIT License](https://github.com/Zeta36/chess-alpha-zero/blob/master/LICENSE.txt) \ No newline at end of file diff --git a/docs/assets/users_guide/carnaval.png b/docs/assets/users_guide/carnaval.png new file mode 100644 index 0000000..3ba98b5 Binary files /dev/null and b/docs/assets/users_guide/carnaval.png differ diff --git a/docs/assets/users_guide/carnaval_colorized.png b/docs/assets/users_guide/carnaval_colorized.png new file mode 100644 index 0000000..8bb43b7 Binary files /dev/null and b/docs/assets/users_guide/carnaval_colorized.png differ diff --git a/docs/assets/users_guide/jucelino.png b/docs/assets/users_guide/jucelino.png new file mode 100644 index 0000000..5bcdf6a Binary files /dev/null and b/docs/assets/users_guide/jucelino.png differ diff --git a/docs/assets/users_guide/jucelino_colorized.png b/docs/assets/users_guide/jucelino_colorized.png new file mode 100644 index 0000000..13b5f35 Binary files /dev/null and b/docs/assets/users_guide/jucelino_colorized.png differ diff --git a/docs/index.html b/docs/index.html index d0c191e..3131b3f 100644 --- a/docs/index.html +++ b/docs/index.html @@ -126,6 +126,22 @@

Free

+
+
+

siggraph-colorization

+
+
+

Free

+ + User's Guide +
+
+

zeta36-chess-alpha-zero

diff --git a/docs/users_guide/cntk-image-recon.md b/docs/users_guide/cntk-image-recon.md index a618403..d16cfbe 100644 --- a/docs/users_guide/cntk-image-recon.md +++ b/docs/users_guide/cntk-image-recon.md @@ -37,10 +37,10 @@ You can use this service from [SingularityNET DApp](http://beta.singularitynet.i You can also call the service from SingularityNET CLI (`snet`). -Assuming that you have an open channel (`id: 0`) to this service: +Assuming that you have an open channel to this service: ``` -$ snet client call 0 0.00000001 54.203.198.53:7004 flowers '{"model": "ResNet152", "img_path": "https://www.fiftyflowers.com/site_files/FiftyFlowers/Image/Product/Mini-Black-Eye-bloom-350_c7d02e72.jpg"}' +$ snet client call snet cntk-image-recon flowers '{"model": "ResNet152", "img_path": "https://www.fiftyflowers.com/site_files/FiftyFlowers/Image/Product/Mini-Black-Eye-bloom-350_c7d02e72.jpg"}' ... Read call params from cmdline... diff --git a/docs/users_guide/i3d-video-action-recognition.md b/docs/users_guide/i3d-video-action-recognition.md index da35a3d..f1da9a6 100644 --- a/docs/users_guide/i3d-video-action-recognition.md +++ b/docs/users_guide/i3d-video-action-recognition.md @@ -33,10 +33,10 @@ You can use this service from [SingularityNET DApp](http://beta.singularitynet.i You can also call the service from SingularityNET CLI (`snet`). -Assuming that you have an open channel (`id: 0`) to this service: +Assuming that you have an open channel to this service: ``` -$ snet client call 0 0.00000001 54.203.198.53:7005 video_action_recon '{"model": "400", "url": "http://crcv.ucf.edu/THUMOS14/UCF101/UCF101/v_CricketShot_g04_c02.avi"}' +$ snet client call snet i3d-video-action-recognition video_action_recon '{"model": "400", "url": "http://crcv.ucf.edu/THUMOS14/UCF101/UCF101/v_CricketShot_g04_c02.avi"}' ... Read call params from cmdline... diff --git a/docs/users_guide/object-detection-image-recon.md b/docs/users_guide/object-detection-image-recon.md index 1d1310f..842aff8 100644 --- a/docs/users_guide/object-detection-image-recon.md +++ b/docs/users_guide/object-detection-image-recon.md @@ -34,10 +34,10 @@ You can use this service from [SingularityNET DApp](http://beta.singularitynet.i You can also call the service from SingularityNET CLI (`snet`). -Assuming that you have an open channel (`id: 0`) to this service: +Assuming that you have an open channel to this service: ``` -$ snet client call 0 0.00000001 54.203.198.53:7006 detect_recon '{"model_detect": "yolov3", "model_recon": "ResNet152", "img_path": "https://figopetinsurance.com/sites/default/files/styles/blog_detail/public/imagedogsman-and-dog-hiking-mountainsblog.jpg", "confidence": "0.5"}' +$ snet client call snet object-detection-image-recon detect_recon '{"model_detect": "yolov3", "model_recon": "ResNet152", "img_path": "https://figopetinsurance.com/sites/default/files/styles/blog_detail/public/imagedogsman-and-dog-hiking-mountainsblog.jpg", "confidence": "0.5"}' ... Read call params from cmdline... diff --git a/docs/users_guide/places365-scene-recognition.md b/docs/users_guide/places365-scene-recognition.md index 635d28b..372dee7 100644 --- a/docs/users_guide/places365-scene-recognition.md +++ b/docs/users_guide/places365-scene-recognition.md @@ -30,14 +30,11 @@ And returns as **output**: You can call the `places365-scene-recognition` service by installing the [SingularityNET Cli](https://github.com/singnet/snet-cli) through its `snet client call` command. Assuming you have an open channel to this service: -1. Use its CHANNEL_ID (e.g.: `270`); -2. Specify a price in AGIs (e.g.: `0`, since its a free service); -3. Point to the endpoint at which this service's [SNET Daemon](https://github.com/singnet/snet-daemon) listens to the blockchain waiting for client calls: `54.203.198.53:7019`. You can obtain this and other information about registered services by running `snet service print_metadata ORGANIZATION SERVICE_NAME`. -4. Filling in the method and some input data as defined in the service's `.proto` file. +1. Fill in the method and some input data as defined in the service's `.proto` file. Example call: ``` -$ snet client call 270 0 54.203.198.53:7019 recognize_scene '{"input_image":"https://static1.squarespace.com/static/564783d5e4b077901c4bdc37/t/5a823d47c83025d76ac6ddae/1518484818865/Piccolo-104.jpg?format=1500w", "predict":"io, categories"}' +$ snet client call snet places365-scene-recognition recognize_scene '{"input_image":"https://static1.squarespace.com/static/564783d5e4b077901c4bdc37/t/5a823d47c83025d76ac6ddae/1518484818865/Piccolo-104.jpg?format=1500w", "predict":"io, categories"}' ... data: "{\"io\": \"indoor\", \"categories\": \" 0.924 -> beauty_salon, 0.006 -> gymnasium/indoor, 0.005 -> clean_room, 0.005 -> biology_laboratory, 0.004 -> chemistry_lab,\"}" ``` diff --git a/docs/users_guide/s2vt-video-captioning.md b/docs/users_guide/s2vt-video-captioning.md index d91907b..a841fd7 100644 --- a/docs/users_guide/s2vt-video-captioning.md +++ b/docs/users_guide/s2vt-video-captioning.md @@ -38,10 +38,10 @@ You can use this service from [SingularityNET DApp](http://beta.singularitynet.i You can also call the service from SingularityNET CLI (`snet`). -Assuming that you have an open channel (`id: 0`) to this service: +Assuming that you have an open channel to this service: ``` -$ snet client call 0 0.00000001 54.203.198.53:7007 video_cap '{"url": "http://crcv.ucf.edu/THUMOS14/UCF101/UCF101/v_PlayingGuitar_g05_c01.avi", "start_time_sec": "0", "stop_time_sec": "0"}' +$ snet client call snet s2vt-video-captioning video_cap '{"url": "http://crcv.ucf.edu/THUMOS14/UCF101/UCF101/v_PlayingGuitar_g05_c01.avi", "start_time_sec": "0", "stop_time_sec": "0"}' ... Read call params from cmdline... diff --git a/docs/users_guide/siggraph-colorization.html b/docs/users_guide/siggraph-colorization.html new file mode 100644 index 0000000..9e10b02 --- /dev/null +++ b/docs/users_guide/siggraph-colorization.html @@ -0,0 +1,81 @@ + + + + + + + + + + SingularityNET Service - siggraph-colorization + + + + + + + + + + + +
+
SingularityNET
+ User's Guide Hub +
+ +
+

siggraph-colorization

+

Service User's Guide

+
+ +
+
+
+ +
+ + + + + + + + + + + + + \ No newline at end of file diff --git a/docs/users_guide/siggraph-colorization.md b/docs/users_guide/siggraph-colorization.md new file mode 100644 index 0000000..6b91081 --- /dev/null +++ b/docs/users_guide/siggraph-colorization.md @@ -0,0 +1,61 @@ +[issue-template]: ../../../issues/new?template=BUG_REPORT.md +[feature-template]: ../../../issues/new?template=FEATURE_REQUEST.md + +![singnetlogo](../assets/singnet-logo.jpg?raw=true 'SingularityNET') + +# Let there be Color! + +This service uses [Let there be Color!](http://iizuka.cs.tsukuba.ac.jp/projects/colorization/en/) to perform colorization on grayscale images. + +It is part of our third party [DNN Model Services](https://github.com/singnet/dnn-model-services). + +### Welcome + +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. + +### What’s the point? + +The service can colorize grayscale images. + +### How does it work? + +The user must provide the following input in order to start the service and get a response: + +Input: + - `img_input`: A grayscale image URL. + +You can use this service from [SingularityNET DApp](http://beta.singularitynet.io/). + +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 colorize '{"img_input": "https://snet-models.s3.amazonaws.com/bh/Colorize/carnaval.jpg"}' + +[Base64 Image] +``` + +### What to expect from this service? + +Input Image: + +![Carnaval Grayscale](../assets/users_guide/carnaval.png) + + +Response: + +![BackpackManDog Splash 1](../assets/users_guide/carnaval_colorized.png) + + +Input Image: + +![Carnaval Grayscale](../assets/users_guide/jucelino.png) + + +Response: + +![BackpackManDog Splash 1](../assets/users_guide/jucelino_colorized.png) + diff --git a/docs/users_guide/yolov3-object-detection.md b/docs/users_guide/yolov3-object-detection.md index 708fabc..e409028 100644 --- a/docs/users_guide/yolov3-object-detection.md +++ b/docs/users_guide/yolov3-object-detection.md @@ -34,10 +34,10 @@ You can use this service from [SingularityNET DApp](http://beta.singularitynet.i You can also call the service from SingularityNET CLI (`snet`). -Assuming that you have an open channel (`id: 0`) to this service: +Assuming that you have an open channel to this service: ``` -$ snet client call 0 0.00000001 54.203.198.53:7008 detect '{"model": "yolov3", "img_path": "https://hips.hearstapps.com/amv-prod-cad-assets.s3.amazonaws.com/images/media/51/2017-10best-lead-photo-672628-s-original.jpg", "confidence": "0.5"}' +$ snet client call snet yolov3-object-detection detect '{"model": "yolov3", "img_path": "https://hips.hearstapps.com/amv-prod-cad-assets.s3.amazonaws.com/images/media/51/2017-10best-lead-photo-672628-s-original.jpg", "confidence": "0.5"}' ... Read call params from cmdline... diff --git a/docs/users_guide/zeta36-chess-alpha-zero.md b/docs/users_guide/zeta36-chess-alpha-zero.md index ab54cd7..47be68c 100644 --- a/docs/users_guide/zeta36-chess-alpha-zero.md +++ b/docs/users_guide/zeta36-chess-alpha-zero.md @@ -71,10 +71,10 @@ You can use this service from [SingularityNET DApp](http://beta.singularitynet.i You can also call the service from SingularityNET CLI (`snet`). -Assuming that you have an open channel (`id: 0`) to this service: +Assuming that you have an open channel to this service: ``` -$ snet client call 0 0.00000001 54.203.198.53:7077 play '{"uid": "my_uid","move": "c2c4"}' +$ snet client call snet zeta36-chess-alpha-zero play '{"uid": "my_uid","move": "c2c4"}' response: UID: my_uid diff --git a/services/cntk-image-recon/README.md b/services/cntk-image-recon/README.md index b83de76..87d91f3 100644 --- a/services/cntk-image-recon/README.md +++ b/services/cntk-image-recon/README.md @@ -1,7 +1,7 @@ [issue-template]: ../../../../../issues/new?template=BUG_REPORT.md [feature-template]: ../../../../../issues/new?template=FEATURE_REQUEST.md -![singnetlogo](../../../docs/assets/singnet-logo.jpg?raw=true 'SingularityNET') +![singnetlogo](../../docs/assets/singnet-logo.jpg 'SingularityNET') # CNTK Image Recognition @@ -14,7 +14,7 @@ It is part of our third party [DNN Model Services](https://github.com/singnet/dn ### Requirements - [Python 3.6.5](https://www.python.org/downloads/release/python-365/) -- [Node 8+ w/npm](https://nodejs.org/en/download/) +- [SNET CLI](https://github.com/singnet/snet-cli) - Pre-trained models (dogs and flowers) ### Development @@ -125,19 +125,13 @@ Image (Link): https://cdn2-www.dogtime.com/assets/uploads/2011/01/file_22950_sta Through SingularityNET (follow this [link](https://dev.singularitynet.io/tutorials/publish/) to learn how to publish a service and open a payment channel to be able to call it): -Assuming that you have an open channel (`id: 0`) to this service: +Assuming that you have an open channel to this service: ``` $ snet client call snet cntk-image-recon flowers '{"model": "ResNet152", "img_path": "https://www.fiftyflowers.com/site_files/FiftyFlowers/Image/Product/Mini-Black-Eye-bloom-350_c7d02e72.jpg"}' -... -Read call params from cmdline... - -Calling service... - - response: - delta_time: '1.5536' - top_5: '{1: ''98.93%: sunflower'', 2: ''00.64%: black-eyed susan'', 3: ''00.16%: - barbeton daisy'', 4: ''00.14%: oxeye daisy'', 5: ''00.03%: daffodil''}' +Price for this call will be 0.00000001 AGI (use -y to remove this warning). Proceed? (y/n): y +delta_time: "2.5509" +top_5: "{1: \'98.93%: sunflower\', 2: \'00.64%: black-eyed susan\', 3: \'00.16%: barbeton daisy\', 4: \'00.14%: oxeye daisy\', 5: \'00.03%: daffodil\'}" ``` ## Contributing and Reporting Issues diff --git a/services/i3d-video-action-recognition/README.md b/services/i3d-video-action-recognition/README.md index 1fd9fd4..ead22e7 100644 --- a/services/i3d-video-action-recognition/README.md +++ b/services/i3d-video-action-recognition/README.md @@ -1,7 +1,7 @@ [issue-template]: ../../../../../issues/new?template=BUG_REPORT.md [feature-template]: ../../../../../issues/new?template=FEATURE_REQUEST.md -![singnetlogo](../../../docs/assets/singnet-logo.jpg?raw=true 'SingularityNET') +![singnetlogo](../../docs/assets/singnet-logo.jpg 'SingularityNET') # I3D Video Action Recognition @@ -14,7 +14,7 @@ It is part of our third party [DNN Model Services](https://github.com/singnet/dn ### Requirements - [Python 3.6.5](https://www.python.org/downloads/release/python-365/) -- [Node 8+ w/npm](https://nodejs.org/en/download/) +- [SNET CLI](https://github.com/singnet/snet-cli) ### Development @@ -113,7 +113,7 @@ Url: http://crcv.ucf.edu/THUMOS14/UCF101/UCF101/v_MoppingFloor_g25_c01.avi Through SingularityNET (follow this [link](https://dev.singularitynet.io/tutorials/publish/) to learn how to publish a service and open a payment channel to be able to call it): -Assuming that you have an open channel (`id: 0`) to this service: +Assuming that you have an open channel to this service: ``` $ snet client call snet i3d-video-action-recognition video_action_recon '{"model": "400", "url": "http://crcv.ucf.edu/THUMOS14/UCF101/UCF101/v_CricketShot_g04_c02.avi"}' diff --git a/services/places365-scene-recognition/README.md b/services/places365-scene-recognition/README.md index e2fc267..2a7aefb 100644 --- a/services/places365-scene-recognition/README.md +++ b/services/places365-scene-recognition/README.md @@ -1,7 +1,7 @@ [issue-template]: ../../../../../issues/new?template=BUG_REPORT.md [feature-template]: ../../../../../issues/new?template=FEATURE_REQUEST.md -![singnetlogo](../../../docs/assets/singnet-logo.jpg?raw=true 'SingularityNET') +![singnetlogo](../../docs/assets/singnet-logo.jpg 'SingularityNET') # Scene Recognition @@ -14,7 +14,7 @@ It is part of our third party [DNN Model Services](https://github.com/singnet/dn ### Requirements - [Python 3.6.5](https://www.python.org/downloads/release/python-365/) -- [Node 8+ w/npm](https://nodejs.org/en/download/) +- [SNET CLI](https://github.com/singnet/snet-cli) - ResNet pre-trained model and scene recognition attributes related files that are automatically downloaded by running the script for the first time. ### Development @@ -121,10 +121,10 @@ Service completed! #### Through SingularityNET > Follow this [link](https://github.com/singnet/wiki/blob/master/tutorials/howToPublishService/README.md) to learn how to publish a service and open a payment channel to be able to call it. -Assuming that you have an open channel (`id: 270`) to this service, you need `0` AGI to call the service at its Daemon's endpoint (`54.203.198.53:7019`). The only call method available for this service is `recognize_scene`, which has been defined at its protobuf file. Specifying the URL to an `input_image` and telling the service what to `predict`, the full example call (and its outputs) would be: +Assuming that you have an open channel to this service, you need `0` AGI to call the service at its Daemon's endpoint (`54.203.198.53:7019`). The only call method available for this service is `recognize_scene`, which has been defined at its protobuf file. Specifying the URL to an `input_image` and telling the service what to `predict`, the full example call (and its outputs) would be: ``` -$ snet client call 270 0 54.203.198.53:7019 recognize_scene '{"input_image":"https://static1.squarespace.com/static/564783d5e4b077901c4bdc37/t/5a823d47c83025d76ac6ddae/1518484818865/Piccolo-104.jpg?format=1500w", "predict":"io, categories"}' +$ snet client call snet places365-scene-recognition recognize_scene '{"input_image":"https://static1.squarespace.com/static/564783d5e4b077901c4bdc37/t/5a823d47c83025d76ac6ddae/1518484818865/Piccolo-104.jpg?format=1500w", "predict":"io, categories"}' ... data: "{\"io\": \"indoor\", \"categories\": \" 0.924 -> beauty_salon, 0.006 -> gymnasium/indoor, 0.005 -> clean_room, 0.005 -> biology_laboratory, 0.004 -> chemistry_lab,\"}" ``` diff --git a/services/s2vt-video-captioning/README.md b/services/s2vt-video-captioning/README.md index 0a67425..7f82a48 100644 --- a/services/s2vt-video-captioning/README.md +++ b/services/s2vt-video-captioning/README.md @@ -1,7 +1,7 @@ [issue-template]: ../../../../../issues/new?template=BUG_REPORT.md [feature-template]: ../../../../../issues/new?template=FEATURE_REQUEST.md -![singnetlogo](../../../docs/assets/singnet-logo.jpg?raw=true 'SingularityNET') +![singnetlogo](../../docs/assets/singnet-logo.jpg 'SingularityNET') # Sequence to Sequence - Video to Text @@ -14,7 +14,7 @@ It is part of our third party [DNN Model Services](https://github.com/singnet/dn ### Requirements - [Python 2.7](https://www.python.org/downloads/release/python-2715/) -- [Node 8+ w/npm](https://nodejs.org/en/download/) +- [SNET CLI](https://github.com/singnet/snet-cli) ### Development @@ -140,7 +140,7 @@ StopTime (s): 0 Through SingularityNET (follow this [link](https://dev.singularitynet.io/tutorials/publish/) to learn how to publish a service and open a payment channel to be able to call it): -Assuming that you have an open channel (`id: 0`) to this service: +Assuming that you have an open channel to this service: ``` $ snet client call snet s2vt-video-captioning video_cap '{"url": "http://crcv.ucf.edu/THUMOS14/UCF101/UCF101/v_PlayingGuitar_g05_c01.avi", "start_time_sec": "0", "stop_time_sec": "0"}' diff --git a/services/siggraph-colorization/Dockerfile b/services/siggraph-colorization/Dockerfile new file mode 100644 index 0000000..074e40b --- /dev/null +++ b/services/siggraph-colorization/Dockerfile @@ -0,0 +1,38 @@ +FROM nightseas/cuda-torch:latest + +ARG git_owner="singnet" +ARG git_repo="dnn-model-services" +ARG git_branch="master" + +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-get update && \ + apt-get install -y \ + git \ + wget \ + nano \ + curl + +RUN apt-get install -y python3 python3-pip + +RUN SNETD_VERSION=`curl -s https://api.github.com/repos/singnet/snet-daemon/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")'` && \ + 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 -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/siggraph-colorization/README.md new file mode 100644 index 0000000..0758f3e --- /dev/null +++ b/services/siggraph-colorization/README.md @@ -0,0 +1,132 @@ +[issue-template]: ../../../../../issues/new?template=BUG_REPORT.md +[feature-template]: ../../../../../issues/new?template=FEATURE_REQUEST.md + +![singnetlogo](../../docs/assets/singnet-logo.jpg 'SingularityNET') + +# Let there be Color! + +This service uses [siggraph2016_colorization](http://iizuka.cs.tsukuba.ac.jp/projects/colorization/en/) to perform +automatic image colorization with simultaneous classification. + +It is part of our third party [DNN Model Services](https://github.com/singnet/dnn-model-services). + +## Getting Started + +### Requirements + +- [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`) + +### Development + +Clone this repository and download the models using the `get_colorize_model.sh` script: + +``` +$ 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 +``` + +### Running the service: + +To get the `ORGANIZATION_ID` and `SERVICE_ID` you must have already published a service (check this [link](https://dev.singularitynet.io/tutorials/publish/)). + +Create the `SNET Daemon`'s config JSON file (`snetd.config.json`). + +``` +{ + "DAEMON_END_POINT": "DAEMON_HOST:DAEMON_PORT", + "ETHEREUM_JSON_RPC_ENDPOINT": "JSON_RPC_ENDPOINT", + "IPFS_END_POINT": "http://ipfs.singularitynet.io:80", + "REGISTRY_ADDRESS_KEY": "REGISTRY_ADDRESS", + "PASSTHROUGH_ENABLED": true, + "PASSTHROUGH_ENDPOINT": "http://SERVICE_GRPC_HOST:SERVICE_GRPC_PORT", + "ORGANIZATION_ID": "ORGANIZATION_ID", + "SERVICE_ID": "SERVICE_ID", + "LOG": { + "LEVEL": "debug", + "OUTPUT": { + "TYPE": "stdout" + } + } +} +``` + +For example (using the Ropsten testnet): + +``` +$ cat snetd.config.json +{ + "DAEMON_END_POINT": "0.0.0.0:7054", + "ETHEREUM_JSON_RPC_ENDPOINT": "https://ropsten.infura.io", + "IPFS_END_POINT": "http://ipfs.singularitynet.io:80", + "REGISTRY_ADDRESS_KEY": "0x5156fde2ca71da4398f8c76763c41bc9633875e4", + "PASSTHROUGH_ENABLED": true, + "PASSTHROUGH_ENDPOINT": "http://localhost:7003", + "ORGANIZATION_ID": "snet", + "SERVICE_ID": "siggraph-colorization", + "LOG": { + "LEVEL": "debug", + "OUTPUT": { + "TYPE": "stdout" + } + } +} +``` + +Note that we set `DAEMON_HOST = 0.0.0.0` because this service will run inside a Docker container. + +Install all dependencies: +``` +$ pip3 install -r requirements.txt +``` +Generate the gRPC codes: +``` +$ sh buildproto.sh +``` +Start the service and `SNET Daemon`: +``` +$ python3 run_colorize_service.py +``` + +### Calling the service: + +Inputs: + - `gRPC method`: colorize. + - `img_input`: An image URL. + +Local (testing purpose): + +``` +$ python3 test_colorize_service.py +Endpoint (localhost:7003): +Method (colorize): colorize +Image (Link): +[Base64 Image] +``` + +Through SingularityNET (follow this [link](https://dev.singularitynet.io/tutorials/publish/) to learn how to publish a service and open a payment channel to be able to call it): + +Assuming that you have an open channel to this service: + +``` +$ snet client call snet siggraph-colorization colorize '{"img_input": "https://snet-models.s3.amazonaws.com/bh/Colorize/carnaval.jpg"}' + +[Base64 Image] + +``` + +## Contributing and Reporting Issues + +Please read our [guidelines](https://dev.singularitynet.io/docs/contribute/contribution-guidelines/#submitting-an-issue) before submitting an issue. If your issue is a bug, please use the bug template pre-populated [here][issue-template]. For feature requests and queries you can use [this template][feature-template]. + +## Authors + +* **Artur Gontijo** - *Maintainer* - [SingularityNET](https://www.singularitynet.io) \ No newline at end of file diff --git a/services/siggraph-colorization/buildproto.sh b/services/siggraph-colorization/buildproto.sh new file mode 100644 index 0000000..f81ce0b --- /dev/null +++ b/services/siggraph-colorization/buildproto.sh @@ -0,0 +1,2 @@ +#! /bin/bash +python3 -m grpc_tools.protoc -I. --python_out=. --grpc_python_out=. service/service_spec/colorization.proto \ No newline at end of file diff --git a/services/siggraph-colorization/colorize.lua b/services/siggraph-colorization/colorize.lua new file mode 100644 index 0000000..2057154 --- /dev/null +++ b/services/siggraph-colorization/colorize.lua @@ -0,0 +1,48 @@ +--[[ + 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/requirements.txt b/services/siggraph-colorization/requirements.txt new file mode 100644 index 0000000..2c655e6 --- /dev/null +++ b/services/siggraph-colorization/requirements.txt @@ -0,0 +1,3 @@ +grpcio>=1.14.2 +grpcio-tools>=1.14.1 +requests==2.20.0 \ No newline at end of file diff --git a/services/siggraph-colorization/run_colorize_service.py b/services/siggraph-colorization/run_colorize_service.py new file mode 100644 index 0000000..acbfc55 --- /dev/null +++ b/services/siggraph-colorization/run_colorize_service.py @@ -0,0 +1,106 @@ +import sys +import os +import signal +import time +import subprocess +import logging +import pathlib +import glob +import json +import argparse + +from service import registry + +logging.basicConfig(level=10, format="%(asctime)s - [%(levelname)8s] - %(name)s - %(message)s") +log = logging.getLogger("run_siggraph_colorization_service") + + +def main(): + parser = argparse.ArgumentParser(description="Run services") + parser.add_argument("--no-daemon", action="store_false", dest="run_daemon", help="do not start the daemon") + parser.add_argument("--ssl", action="store_true", dest="run_ssl", help="start the daemon with SSL") + args = parser.parse_args() + root_path = pathlib.Path(__file__).absolute().parent + + # All services modules go here + service_modules = ["service.siggraph_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) + + # Continuous checking all subprocess + try: + while True: + for p in all_p: + p.poll() + if p.returncode and p.returncode != 0: + kill_and_exit(all_p) + time.sleep(1) + except Exception as e: + log.error(e) + raise + + +def start_all_services(cwd, service_modules, run_daemon, run_ssl): + """ + Loop through all service_modules and start them. + For each one, an instance of Daemon "snetd" is created. + snetd will start with configs from "snetd.config.json" + """ + all_p = [] + for i, service_module in enumerate(service_modules): + service_name = service_module.split(".")[-1] + log.info("Launching {} on port {}".format(str(registry[service_name]), service_module)) + all_p += start_service(cwd, service_module, run_daemon, run_ssl) + return all_p + + +def start_service(cwd, service_module, run_daemon, run_ssl): + """ + Starts SNET Daemon ("snetd") and the python module of the service + at the passed gRPC port. + """ + + def add_ssl_configs(conf): + """Add SSL keys to snetd.config.json""" + with open(conf, "r") as f: + snetd_configs = json.load(f) + snetd_configs["ssl_cert"] = "/opt/singnet/.certs/fullchain.pem" + snetd_configs["ssl_key"] = "/opt/singnet/.certs/privkey.pem" + with open(conf, "w") as f: + json.dump(snetd_configs, f, sort_keys=True, indent=4) + + all_p = [] + if run_daemon: + for idx, config_file in enumerate(glob.glob("./snetd_configs/*.json")): + if run_ssl: + add_ssl_configs(config_file) + all_p.append(start_snetd(str(cwd), config_file)) + service_name = service_module.split(".")[-1] + grpc_port = registry[service_name]["grpc"] + p = subprocess.Popen([sys.executable, "-m", service_module, "--grpc-port", str(grpc_port)], cwd=str(cwd)) + all_p.append(p) + return all_p + + +def start_snetd(cwd, config_file=None): + """ + Starts the Daemon "snetd": + """ + cmd = ["snetd", "serve"] + if config_file: + cmd = ["snetd", "serve", "--config", config_file] + return subprocess.Popen(cmd, cwd=str(cwd)) + + +def kill_and_exit(all_p): + for p in all_p: + try: + os.kill(p.pid, signal.SIGTERM) + except Exception as e: + log.error(e) + exit(1) + + +if __name__ == "__main__": + main() diff --git a/services/siggraph-colorization/service/__init__.py b/services/siggraph-colorization/service/__init__.py new file mode 100644 index 0000000..c9487b4 --- /dev/null +++ b/services/siggraph-colorization/service/__init__.py @@ -0,0 +1,5 @@ +registry = { + "siggraph_colorization_service": { + "grpc": 7013, + }, +} \ No newline at end of file diff --git a/services/siggraph-colorization/service/common.py b/services/siggraph-colorization/service/common.py new file mode 100644 index 0000000..21aa4e5 --- /dev/null +++ b/services/siggraph-colorization/service/common.py @@ -0,0 +1,29 @@ +import argparse +import os.path +import time + +from service import registry + + +def common_parser(script_name): + parser = argparse.ArgumentParser(prog=script_name) + service_name = os.path.splitext(os.path.basename(script_name))[0] + parser.add_argument("--grpc-port", + help="port to bind gRPC service to", + default=registry[service_name]['grpc'], + type=int, + required=False) + return parser + + +# From gRPC docs: +# Because start() does not block you may need to sleep-loop if there is nothing +# else for your code to do while serving. +def main_loop(grpc_handler, args): + server = grpc_handler(port=args.grpc_port) + server.start() + try: + while True: + time.sleep(1) + except KeyboardInterrupt: + server.stop(0) diff --git a/services/siggraph-colorization/service/service_spec/colorization.proto b/services/siggraph-colorization/service/service_spec/colorization.proto new file mode 100644 index 0000000..b552129 --- /dev/null +++ b/services/siggraph-colorization/service/service_spec/colorization.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; + +message Input { + string img_input = 1; +} + +message Output { + string img_colorized = 1; +} + +service Colorization { + rpc colorize(Input) returns (Output) {} +} \ No newline at end of file diff --git a/services/siggraph-colorization/service/siggraph_colorization.py b/services/siggraph-colorization/service/siggraph_colorization.py new file mode 100644 index 0000000..1251e7b --- /dev/null +++ b/services/siggraph-colorization/service/siggraph_colorization.py @@ -0,0 +1,90 @@ +import os +import requests +import hashlib +import datetime +import subprocess +import base64 +import logging +import traceback + +logging.basicConfig(level=10, format="%(asctime)s - [%(levelname)8s] - %(name)s - %(message)s") +log = logging.getLogger("siggraph_colorization") + + +class Colorization: + def __init__(self, img_input): + self.img_input = img_input + 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(): + # Setting a hash accordingly to the timestamp + seed = "{}".format(datetime.datetime.now()) + m = hashlib.sha256() + m.update(seed.encode("utf-8")) + m = m.hexdigest() + # Returns only the first and the last 10 hex + 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...") + header = {'User-Agent': 'Mozilla/5.0 (Windows NT x.y; Win64; x64; rv:9.0) Gecko/20100101 Firefox/10.0'} + r = requests.get(self.img_input, headers=header, allow_redirects=True) + 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...") + with open(input_file, "wb") as fd: + 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() + + self.response["img_colorized"] = "Fail" + with open(output_img, "rb") as base64_file: + self.response["img_colorized"] = base64.b64encode(base64_file.read()) + + if os.path.exists(input_file): + os.remove(input_file) + if os.path.exists(output_img): + os.remove(output_img) + + return self.response + + except Exception as e: + log.error(e) + traceback.print_exc() + self.response["img_colorized"] = "Fail" + return self.response diff --git a/services/siggraph-colorization/service/siggraph_colorization_service.py b/services/siggraph-colorization/service/siggraph_colorization_service.py new file mode 100644 index 0000000..3b33674 --- /dev/null +++ b/services/siggraph-colorization/service/siggraph_colorization_service.py @@ -0,0 +1,69 @@ +import sys +import time +import logging +import traceback + +import grpc +import concurrent.futures as futures + +import service.common +from service.siggraph_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") + + +# Create a class to be added to the gRPC server +# derived from the protobuf codes. +class ColorizationServicer(grpc_bt_grpc.ColorizationServicer): + def __init__(self): + self.response = Output() + log.debug("ColorizationServicer created") + + # 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): + try: + sig_colorize = Colorization(request.img_input) + tmp_response = sig_colorize.colorize() + + # To respond we need to fill this "img_colorized" field of Output() object (from .proto file) + self.response.img_colorized = tmp_response["img_colorized"] + + log.debug("translate({})={}".format(request.img_input[:50], self.response.img_colorized[:50])) + return self.response + + except Exception as e: + traceback.print_exc() + log.error(e) + self.response.img_colorized = "Fail" + return self.response + + +# The gRPC serve function. +# +# Params: +# max_workers: pool of threads to execute calls asynchronously +# port: gRPC server port +# +# Add all your classes to the server here. +# (from generated .py files by protobuf compiler) +def serve(max_workers=10, port=7777): + server = grpc.server(futures.ThreadPoolExecutor(max_workers=max_workers)) + grpc_bt_grpc.add_ColorizationServicer_to_server(ColorizationServicer(), server) + server.add_insecure_port("[::]:{}".format(port)) + return server + + +if __name__ == "__main__": + """ + Runs the gRPC server to communicate with the Snet Daemon. + """ + parser = service.common.common_parser(__file__) + args = parser.parse_args(sys.argv[1:]) + service.common.main_loop(serve, args) diff --git a/services/siggraph-colorization/snetd_configs/snetd.mainnet b/services/siggraph-colorization/snetd_configs/snetd.mainnet new file mode 100644 index 0000000..3e999de --- /dev/null +++ b/services/siggraph-colorization/snetd_configs/snetd.mainnet @@ -0,0 +1,38 @@ +{ + "daemon_end_point": "0.0.0.0:7035", + "ethereum_json_rpc_endpoint": "https://mainnet.infura.io", + "ipfs_end_point": "http://ipfs.singularitynet.io:80", + "registry_address_key": "0xb3180a92e210b45e3447976a412ac0df859febaf", + "passthrough_enabled": true, + "passthrough_endpoint": "http://localhost:7013", + "organization_id": "snet", + "service_id": "siggraph-colorization", + + "payment_channel_storage_server": { + "id": "storage-mainnet", + "host": "127.0.0.1", + "client_port": 2379, + "peer_port": 2380, + "token": "unique-token", + "cluster": "storage-mainnet=http://127.0.0.1:2380", + "data_dir": "etcd/storage-data-dir-mainnet.etcd", + "enabled": true + }, + + "payment_channel_storage_client": { + "connection_timeout": "5s", + "request_timeout": "3s", + "endpoints": ["http://127.0.0.1:2379"] + }, + + "log": { + "level": "debug", + "output": { + "current_link": "./snetd-mainnet.log", + "file_pattern": "./snetd-mainnet.%Y%m%d.log", + "rotation_count": 0, + "rotation_time_in_sec": 86400, + "type": "file" + } + } +} \ No newline at end of file diff --git a/services/siggraph-colorization/snetd_configs/snetd.ropsten.json b/services/siggraph-colorization/snetd_configs/snetd.ropsten.json new file mode 100644 index 0000000..0aa76f4 --- /dev/null +++ b/services/siggraph-colorization/snetd_configs/snetd.ropsten.json @@ -0,0 +1,38 @@ +{ + "daemon_end_point": "0.0.0.0:7085", + "ethereum_json_rpc_endpoint": "https://ropsten.infura.io", + "ipfs_end_point": "http://ipfs.singularitynet.io:80", + "registry_address_key": "0x5156fde2ca71da4398f8c76763c41bc9633875e4", + "passthrough_enabled": true, + "passthrough_endpoint": "http://localhost:7013", + "organization_id": "snet", + "service_id": "siggraph-colorization", + + "payment_channel_storage_server": { + "id": "storage-ropsten", + "host": "127.0.0.1", + "client_port": 2381, + "peer_port": 2382, + "token": "unique-token", + "cluster": "storage-ropsten=http://127.0.0.1:2382", + "data_dir": "etcd/storage-data-dir-ropsten.etcd", + "enabled": true + }, + + "payment_channel_storage_client": { + "connection_timeout": "5s", + "request_timeout": "3s", + "endpoints": ["http://127.0.0.1:2381"] + }, + + "log": { + "level": "debug", + "output": { + "current_link": "./snetd-ropsten.log", + "file_pattern": "./snetd-ropsten.%Y%m%d.log", + "rotation_count": 0, + "rotation_time_in_sec": 86400, + "type": "file" + } + } +} \ No newline at end of file diff --git a/services/siggraph-colorization/test_colorize_service.py b/services/siggraph-colorization/test_colorize_service.py new file mode 100644 index 0000000..bd664d9 --- /dev/null +++ b/services/siggraph-colorization/test_colorize_service.py @@ -0,0 +1,48 @@ +import sys +import grpc + +# import the generated classes +import service.service_spec.colorization_pb2_grpc as grpc_bt_grpc +import service.service_spec.colorization_pb2 as grpc_bt_pb2 + +from service import registry + +TEST_URL = "https://raw.githubusercontent.com/singnet/dnn-model-services/master/docs/assets/users_guide/rose.jpg" + +if __name__ == "__main__": + + try: + test_flag = False + if len(sys.argv) == 2: + if sys.argv[1] == "auto": + test_flag = True + + endpoint = input("Endpoint (localhost:{}): ".format(registry["siggraph_colorization_service"]["grpc"])) if not test_flag else "" + if endpoint == "": + endpoint = "localhost:{}".format(registry["siggraph_colorization_service"]["grpc"]) + + # open a gRPC channel + channel = grpc.insecure_channel("{}".format(endpoint)) + + grpc_method = input("Method (colorize): ") if not test_flag else "colorize" + if grpc_method == "": + grpc_method = "colorize" + + img_input = input("Image (Link): ") if not test_flag else TEST_URL + + stub = grpc_bt_grpc.ColorizationStub(channel) + number = grpc_bt_pb2.Input(img_input=img_input) + + if grpc_method == "colorize": + response = stub.colorize(number) + print(response.img_colorized) + + if response.img_colorized == "Fail": + exit(1) + else: + print("Invalid method!") + exit(1) + + except Exception as e: + print(e) + exit(1) diff --git a/services/yolov3-object-detection/README.md b/services/yolov3-object-detection/README.md index 3e412cc..35bd064 100644 --- a/services/yolov3-object-detection/README.md +++ b/services/yolov3-object-detection/README.md @@ -1,7 +1,7 @@ [issue-template]: ../../../../../issues/new?template=BUG_REPORT.md [feature-template]: ../../../../../issues/new?template=FEATURE_REQUEST.md -![singnetlogo](../../../docs/assets/singnet-logo.jpg?raw=true 'SingularityNET') +![singnetlogo](../../docs/assets/singnet-logo.jpg 'SingularityNET') # Object Detection @@ -14,7 +14,7 @@ It is part of our third party [DNN Model Services](https://github.com/singnet/dn ### Requirements - [Python 3.6.5](https://www.python.org/downloads/release/python-365/) -- [Node 8+ w/npm](https://nodejs.org/en/download/) +- [SNET CLI](https://github.com/singnet/snet-cli) - YOLOv3 files: `yolov3.weights` and `yolov3.cfg` ### Development @@ -118,7 +118,7 @@ confidences: "[0.9988894462585449, 0.9795901775360107, 0.9754813313484192]" Through SingularityNET (follow this [link](https://dev.singularitynet.io/tutorials/publish/) to learn how to publish a service and open a payment channel to be able to call it): -Assuming that you have an open channel (`id: 0`) to this service: +Assuming that you have an open channel to this service: ``` $ snet client call snet yolov3-object-detection detect '{"model": "yolov3", "img_path": "https://hips.hearstapps.com/amv-prod-cad-assets.s3.amazonaws.com/images/media/51/2017-10best-lead-photo-672628-s-original.jpg", "confidence": "0.5"}' diff --git a/services/zeta36-chess-alpha-zero/README.md b/services/zeta36-chess-alpha-zero/README.md index 65c5684..8b5b134 100644 --- a/services/zeta36-chess-alpha-zero/README.md +++ b/services/zeta36-chess-alpha-zero/README.md @@ -1,7 +1,7 @@ [issue-template]: ../../../../../issues/new?template=BUG_REPORT.md [feature-template]: ../../../../../issues/new?template=FEATURE_REQUEST.md -![singnetlogo](../../../docs/assets/singnet-logo.jpg?raw=true 'SingularityNET') +![singnetlogo](../../docs/assets/singnet-logo.jpg 'SingularityNET') # Chess Alpha Zero @@ -15,7 +15,7 @@ It is part of our third party [DNN Model Services](https://github.com/singnet/dn ### Requirements - [Python 3.6.5](https://www.python.org/downloads/release/python-365/) -- [Node 8+ w/npm](https://nodejs.org/en/download/) +- [SNET CLI](https://github.com/singnet/snet-cli) ### Development @@ -188,7 +188,7 @@ status: game_running: g7g6 Through SingularityNET (follow this [link](https://dev.singularitynet.io/tutorials/publish/) to learn how to publish a service and open a payment channel to be able to call it): -Assuming that you have an open channel (`id: 0`) to this service: +Assuming that you have an open channel to this service: ``` $ snet client call snet zeta36-chess-alpha-zero play '{"move": "g1f3"}' diff --git a/utils/get_colorize_model.sh b/utils/get_colorize_model.sh new file mode 100644 index 0000000..bd38090 --- /dev/null +++ b/utils/get_colorize_model.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +DIR="./Resources/Models" +if [ ! -d "$DIR" ]; then + mkdir -p ${DIR} +fi + +cd ${DIR} + +# md5sum c88fa2bb6dc9f942a492a7dc7009b966 +# sha1sum d397faf0b63a173680824474bfeab4725c375ca2 +FILENAME="colornet.t7" +FILEURL="http://hi.cs.waseda.ac.jp/~iizuka/data/colornet.t7" +FILEMD5="c88fa2bb6dc9f942a492a7dc7009b966" + +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 }'` +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 +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