うみゅ commited on
Commit
2ad487d
·
unverified ·
2 Parent(s): 35bc132 aa5debc

Merge pull request #3 from umyuu/feature/0.0.3

Browse files
README.md CHANGED
@@ -1,10 +1,20 @@
1
- # SaliencyMap
 
 
 
 
 
 
2
  ## 概要
3
  顕著性マップを表示するデモアプリです。
4
  私は画像処理についてはまだ初心者ですが、興味を持っています。
5
  > **技術的なお話**
6
  > opencv-contribパッケージの`cv2.saliency.StaticSaliencySpectralResidual`を呼び出すラッパーアプリです。
7
 
 
 
 
 
8
  ## 導入方法
9
  ### 1. セットアップ
10
  - 以下のファイルをダブルクリックします。
@@ -16,13 +26,13 @@
16
  ~~~
17
  run.bat
18
  ~~~
19
- 2. 実行するとブラウザが起動し[http://127.0.0.1:9999](http://127.0.0.1:9999)を開きます。
20
  > **NOTE**
21
  > デフォルトポート番号は、9999です。
22
  > アプリが起動せずポート番号を変更する時は、メモ帳で`run.bat`を開きの以下行の9999を別の数字(8888)などに変更し保存してください。
23
- > python src\launch.py --server_port 9999
24
  > REM 変更後
25
- > python src\launch.py --server_port 8888
26
 
27
  ## 補足事項
28
  - ローカルで処理が完結します。画像を外部には送信しません。
@@ -38,4 +48,4 @@ run.bat
38
  ~~~
39
 
40
  ## Source code License.
41
- [MIT License](LICENSE)
 
1
+ <div align="center">
2
+
3
+ ![Python version](https://img.shields.io/badge/python-3.8+-important) |
4
+ <a href="https://colab.research.google.com/github/umyuu/SaliencyMapDemo/blob/main/launch_app.ipynb" target="_parent"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Open In Colab"/></a>
5
+ </div>
6
+
7
+ # SaliencyMap — in Python
8
  ## 概要
9
  顕著性マップを表示するデモアプリです。
10
  私は画像処理についてはまだ初心者ですが、興味を持っています。
11
  > **技術的なお話**
12
  > opencv-contribパッケージの`cv2.saliency.StaticSaliencySpectralResidual`を呼び出すラッパーアプリです。
13
 
14
+ ## システム要件
15
+ - 必要ディスク容量:500MB(Pythonを含みません)
16
+ - [Python](https://www.python.org/downloads/)をリンク先からダウンロードしてください。
17
+
18
  ## 導入方法
19
  ### 1. セットアップ
20
  - 以下のファイルをダブルクリックします。
 
26
  ~~~
27
  run.bat
28
  ~~~
29
+ 2. 実行するとブラウザが起動し[http://127.0.0.1:9999](http://127.0.0.1:9999)を開きます。
30
  > **NOTE**
31
  > デフォルトポート番号は、9999です。
32
  > アプリが起動せずポート番号を変更する時は、メモ帳で`run.bat`を開きの以下行の9999を別の数字(8888)などに変更し保存してください。
33
+ > python app.py --server_port 9999
34
  > REM 変更後
35
+ > python app.py --server_port 8888
36
 
37
  ## 補足事項
38
  - ローカルで処理が完結します。画像を外部には送信しません。
 
48
  ~~~
49
 
50
  ## Source code License.
51
+ [MIT License](LICENSE)
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ SaliencyMapDemo
4
+ """
5
+ import argparse
6
+
7
+ import src.utils as utils
8
+ from src.reporter import get_current_reporter
9
+
10
+ PROGRAM_NAME = 'SaliencyMapDemo'
11
+ __version__ = utils.get_package_version()
12
+
13
+ def main():
14
+ """
15
+ エントリーポイント
16
+ 1, コマンドライン引数の解析を行います
17
+ 2, アプリを起動します。
18
+ """
19
+ log = get_current_reporter()
20
+ log.info("#アプリ起動中")
21
+ watch = utils.Stopwatch.startNew()
22
+
23
+ from src.myapp import runApp
24
+
25
+ parser = argparse.ArgumentParser(prog=PROGRAM_NAME, description="SaliencyMapDemo")
26
+ parser.add_argument('--server_port', type=int, default=9999, help="Gradio server port")
27
+ parser.add_argument('--max_file_size', type=int, default=20 * 1024 * 1024, help="Gradio max file size")
28
+ parser.add_argument('--inbrowser', type=bool, default=True, help="Gradio inbrowser")
29
+ parser.add_argument('--share', type=bool, default=False, help="Gradio share")
30
+ parser.add_argument('--version', action='version', version=f'%(prog)s {__version__}')
31
+
32
+ args = parser.parse_args()
33
+
34
+ runApp(args, watch)
35
+
36
+ if __name__ == "__main__":
37
+ main()
assets/hot.webp ADDED
assets/jet.webp ADDED
launch_app.ipynb ADDED
@@ -0,0 +1,310 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "nbformat": 4,
3
+ "nbformat_minor": 0,
4
+ "metadata": {
5
+ "colab": {
6
+ "provenance": []
7
+ },
8
+ "kernelspec": {
9
+ "name": "python3",
10
+ "display_name": "Python 3"
11
+ },
12
+ "language_info": {
13
+ "name": "python"
14
+ }
15
+ },
16
+ "cells": [
17
+ {
18
+ "cell_type": "markdown",
19
+ "source": [
20
+ "# アプリのインストール"
21
+ ],
22
+ "metadata": {
23
+ "id": "QBBnZWaddxv4"
24
+ }
25
+ },
26
+ {
27
+ "cell_type": "code",
28
+ "source": [
29
+ "%cd /content"
30
+ ],
31
+ "metadata": {
32
+ "colab": {
33
+ "base_uri": "https://localhost:8080/"
34
+ },
35
+ "id": "7a5Rf_Qee3N1",
36
+ "outputId": "c3890145-930e-4889-e57e-22321250461f"
37
+ },
38
+ "execution_count": 1,
39
+ "outputs": [
40
+ {
41
+ "output_type": "stream",
42
+ "name": "stdout",
43
+ "text": [
44
+ "/content\n"
45
+ ]
46
+ }
47
+ ]
48
+ },
49
+ {
50
+ "cell_type": "code",
51
+ "execution_count": 2,
52
+ "metadata": {
53
+ "colab": {
54
+ "base_uri": "https://localhost:8080/"
55
+ },
56
+ "id": "fYM7KJOfdPuK",
57
+ "outputId": "79470848-c908-4f7c-81c4-6aeb353498b8"
58
+ },
59
+ "outputs": [
60
+ {
61
+ "output_type": "stream",
62
+ "name": "stdout",
63
+ "text": [
64
+ "Cloning into 'SaliencyMapDemo'...\n",
65
+ "remote: Enumerating objects: 84, done.\u001b[K\n",
66
+ "remote: Counting objects: 100% (84/84), done.\u001b[K\n",
67
+ "remote: Compressing objects: 100% (64/64), done.\u001b[K\n",
68
+ "remote: Total 84 (delta 36), reused 47 (delta 18), pack-reused 0\u001b[K\n",
69
+ "Receiving objects: 100% (84/84), 29.23 KiB | 9.74 MiB/s, done.\n",
70
+ "Resolving deltas: 100% (36/36), done.\n"
71
+ ]
72
+ }
73
+ ],
74
+ "source": [
75
+ "!git clone https://github.com/umyuu/SaliencyMapDemo.git"
76
+ ]
77
+ },
78
+ {
79
+ "cell_type": "code",
80
+ "source": [
81
+ "%cd SaliencyMapDemo"
82
+ ],
83
+ "metadata": {
84
+ "colab": {
85
+ "base_uri": "https://localhost:8080/"
86
+ },
87
+ "id": "H0HI3iKRenJB",
88
+ "outputId": "770d3024-43a2-4282-f59d-bc496cba9cf6"
89
+ },
90
+ "execution_count": 3,
91
+ "outputs": [
92
+ {
93
+ "output_type": "stream",
94
+ "name": "stdout",
95
+ "text": [
96
+ "/content/SaliencyMapDemo\n"
97
+ ]
98
+ }
99
+ ]
100
+ },
101
+ {
102
+ "cell_type": "code",
103
+ "execution_count": 4,
104
+ "metadata": {
105
+ "colab": {
106
+ "base_uri": "https://localhost:8080/"
107
+ },
108
+ "id": "UxrRgQpmDK_g",
109
+ "outputId": "235c6006-55cd-4c1a-d20d-fadd40488f07"
110
+ },
111
+ "outputs": [
112
+ {
113
+ "output_type": "stream",
114
+ "name": "stdout",
115
+ "text": [
116
+ "Collecting gradio==4.28.3 (from -r requirements.txt (line 1))\n",
117
+ " Downloading gradio-4.28.3-py3-none-any.whl (12.2 MB)\n",
118
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m12.2/12.2 MB\u001b[0m \u001b[31m25.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
119
+ "\u001b[?25hCollecting gradio_client==0.16.0 (from -r requirements.txt (line 2))\n",
120
+ " Downloading gradio_client-0.16.0-py3-none-any.whl (314 kB)\n",
121
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m314.4/314.4 kB\u001b[0m \u001b[31m35.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
122
+ "\u001b[?25hCollecting opencv-python==4.9.0.80 (from -r requirements.txt (line 3))\n",
123
+ " Downloading opencv_python-4.9.0.80-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (62.2 MB)\n",
124
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m62.2/62.2 MB\u001b[0m \u001b[31m10.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
125
+ "\u001b[?25hCollecting opencv-contrib-python==4.9.0.80 (from -r requirements.txt (line 4))\n",
126
+ " Downloading opencv_contrib_python-4.9.0.80-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (68.3 MB)\n",
127
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m68.3/68.3 MB\u001b[0m \u001b[31m8.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
128
+ "\u001b[?25hCollecting aiofiles<24.0,>=22.0 (from gradio==4.28.3->-r requirements.txt (line 1))\n",
129
+ " Downloading aiofiles-23.2.1-py3-none-any.whl (15 kB)\n",
130
+ "Requirement already satisfied: altair<6.0,>=4.2.0 in /usr/local/lib/python3.10/dist-packages (from gradio==4.28.3->-r requirements.txt (line 1)) (4.2.2)\n",
131
+ "Collecting fastapi (from gradio==4.28.3->-r requirements.txt (line 1))\n",
132
+ " Downloading fastapi-0.111.0-py3-none-any.whl (91 kB)\n",
133
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m92.0/92.0 kB\u001b[0m \u001b[31m13.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
134
+ "\u001b[?25hCollecting ffmpy (from gradio==4.28.3->-r requirements.txt (line 1))\n",
135
+ " Downloading ffmpy-0.3.2.tar.gz (5.5 kB)\n",
136
+ " Preparing metadata (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
137
+ "Collecting httpx>=0.24.1 (from gradio==4.28.3->-r requirements.txt (line 1))\n",
138
+ " Downloading httpx-0.27.0-py3-none-any.whl (75 kB)\n",
139
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m75.6/75.6 kB\u001b[0m \u001b[31m11.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
140
+ "\u001b[?25hRequirement already satisfied: huggingface-hub>=0.19.3 in /usr/local/lib/python3.10/dist-packages (from gradio==4.28.3->-r requirements.txt (line 1)) (0.20.3)\n",
141
+ "Requirement already satisfied: importlib-resources<7.0,>=1.3 in /usr/local/lib/python3.10/dist-packages (from gradio==4.28.3->-r requirements.txt (line 1)) (6.4.0)\n",
142
+ "Requirement already satisfied: jinja2<4.0 in /usr/local/lib/python3.10/dist-packages (from gradio==4.28.3->-r requirements.txt (line 1)) (3.1.4)\n",
143
+ "Requirement already satisfied: markupsafe~=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio==4.28.3->-r requirements.txt (line 1)) (2.1.5)\n",
144
+ "Requirement already satisfied: matplotlib~=3.0 in /usr/local/lib/python3.10/dist-packages (from gradio==4.28.3->-r requirements.txt (line 1)) (3.7.1)\n",
145
+ "Requirement already satisfied: numpy~=1.0 in /usr/local/lib/python3.10/dist-packages (from gradio==4.28.3->-r requirements.txt (line 1)) (1.25.2)\n",
146
+ "Collecting orjson~=3.0 (from gradio==4.28.3->-r requirements.txt (line 1))\n",
147
+ " Downloading orjson-3.10.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (142 kB)\n",
148
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m142.5/142.5 kB\u001b[0m \u001b[31m20.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
149
+ "\u001b[?25hRequirement already satisfied: packaging in /usr/local/lib/python3.10/dist-packages (from gradio==4.28.3->-r requirements.txt (line 1)) (24.0)\n",
150
+ "Requirement already satisfied: pandas<3.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from gradio==4.28.3->-r requirements.txt (line 1)) (2.0.3)\n",
151
+ "Requirement already satisfied: pillow<11.0,>=8.0 in /usr/local/lib/python3.10/dist-packages (from gradio==4.28.3->-r requirements.txt (line 1)) (9.4.0)\n",
152
+ "Requirement already satisfied: pydantic>=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio==4.28.3->-r requirements.txt (line 1)) (2.7.1)\n",
153
+ "Collecting pydub (from gradio==4.28.3->-r requirements.txt (line 1))\n",
154
+ " Downloading pydub-0.25.1-py2.py3-none-any.whl (32 kB)\n",
155
+ "Collecting python-multipart>=0.0.9 (from gradio==4.28.3->-r requirements.txt (line 1))\n",
156
+ " Downloading python_multipart-0.0.9-py3-none-any.whl (22 kB)\n",
157
+ "Requirement already satisfied: pyyaml<7.0,>=5.0 in /usr/local/lib/python3.10/dist-packages (from gradio==4.28.3->-r requirements.txt (line 1)) (6.0.1)\n",
158
+ "Collecting ruff>=0.2.2 (from gradio==4.28.3->-r requirements.txt (line 1))\n",
159
+ " Downloading ruff-0.4.4-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.7 MB)\n",
160
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m8.7/8.7 MB\u001b[0m \u001b[31m91.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
161
+ "\u001b[?25hCollecting semantic-version~=2.0 (from gradio==4.28.3->-r requirements.txt (line 1))\n",
162
+ " Downloading semantic_version-2.10.0-py2.py3-none-any.whl (15 kB)\n",
163
+ "Collecting tomlkit==0.12.0 (from gradio==4.28.3->-r requirements.txt (line 1))\n",
164
+ " Downloading tomlkit-0.12.0-py3-none-any.whl (37 kB)\n",
165
+ "Collecting typer<1.0,>=0.12 (from gradio==4.28.3->-r requirements.txt (line 1))\n",
166
+ " Downloading typer-0.12.3-py3-none-any.whl (47 kB)\n",
167
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m47.2/47.2 kB\u001b[0m \u001b[31m6.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
168
+ "\u001b[?25hRequirement already satisfied: typing-extensions~=4.0 in /usr/local/lib/python3.10/dist-packages (from gradio==4.28.3->-r requirements.txt (line 1)) (4.11.0)\n",
169
+ "Requirement already satisfied: urllib3~=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio==4.28.3->-r requirements.txt (line 1)) (2.0.7)\n",
170
+ "Collecting uvicorn>=0.14.0 (from gradio==4.28.3->-r requirements.txt (line 1))\n",
171
+ " Downloading uvicorn-0.29.0-py3-none-any.whl (60 kB)\n",
172
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m60.8/60.8 kB\u001b[0m \u001b[31m8.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
173
+ "\u001b[?25hRequirement already satisfied: fsspec in /usr/local/lib/python3.10/dist-packages (from gradio_client==0.16.0->-r requirements.txt (line 2)) (2023.6.0)\n",
174
+ "Collecting websockets<12.0,>=10.0 (from gradio_client==0.16.0->-r requirements.txt (line 2))\n",
175
+ " Downloading websockets-11.0.3-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (129 kB)\n",
176
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m129.9/129.9 kB\u001b[0m \u001b[31m19.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
177
+ "\u001b[?25hRequirement already satisfied: entrypoints in /usr/local/lib/python3.10/dist-packages (from altair<6.0,>=4.2.0->gradio==4.28.3->-r requirements.txt (line 1)) (0.4)\n",
178
+ "Requirement already satisfied: jsonschema>=3.0 in /usr/local/lib/python3.10/dist-packages (from altair<6.0,>=4.2.0->gradio==4.28.3->-r requirements.txt (line 1)) (4.19.2)\n",
179
+ "Requirement already satisfied: toolz in /usr/local/lib/python3.10/dist-packages (from altair<6.0,>=4.2.0->gradio==4.28.3->-r requirements.txt (line 1)) (0.12.1)\n",
180
+ "Requirement already satisfied: anyio in /usr/local/lib/python3.10/dist-packages (from httpx>=0.24.1->gradio==4.28.3->-r requirements.txt (line 1)) (3.7.1)\n",
181
+ "Requirement already satisfied: certifi in /usr/local/lib/python3.10/dist-packages (from httpx>=0.24.1->gradio==4.28.3->-r requirements.txt (line 1)) (2024.2.2)\n",
182
+ "Collecting httpcore==1.* (from httpx>=0.24.1->gradio==4.28.3->-r requirements.txt (line 1))\n",
183
+ " Downloading httpcore-1.0.5-py3-none-any.whl (77 kB)\n",
184
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m77.9/77.9 kB\u001b[0m \u001b[31m11.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
185
+ "\u001b[?25hRequirement already satisfied: idna in /usr/local/lib/python3.10/dist-packages (from httpx>=0.24.1->gradio==4.28.3->-r requirements.txt (line 1)) (3.7)\n",
186
+ "Requirement already satisfied: sniffio in /usr/local/lib/python3.10/dist-packages (from httpx>=0.24.1->gradio==4.28.3->-r requirements.txt (line 1)) (1.3.1)\n",
187
+ "Collecting h11<0.15,>=0.13 (from httpcore==1.*->httpx>=0.24.1->gradio==4.28.3->-r requirements.txt (line 1))\n",
188
+ " Downloading h11-0.14.0-py3-none-any.whl (58 kB)\n",
189
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m58.3/58.3 kB\u001b[0m \u001b[31m9.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
190
+ "\u001b[?25hRequirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.19.3->gradio==4.28.3->-r requirements.txt (line 1)) (3.14.0)\n",
191
+ "Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.19.3->gradio==4.28.3->-r requirements.txt (line 1)) (2.31.0)\n",
192
+ "Requirement already satisfied: tqdm>=4.42.1 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.19.3->gradio==4.28.3->-r requirements.txt (line 1)) (4.66.4)\n",
193
+ "Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio==4.28.3->-r requirements.txt (line 1)) (1.2.1)\n",
194
+ "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio==4.28.3->-r requirements.txt (line 1)) (0.12.1)\n",
195
+ "Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio==4.28.3->-r requirements.txt (line 1)) (4.51.0)\n",
196
+ "Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio==4.28.3->-r requirements.txt (line 1)) (1.4.5)\n",
197
+ "Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio==4.28.3->-r requirements.txt (line 1)) (3.1.2)\n",
198
+ "Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio==4.28.3->-r requirements.txt (line 1)) (2.8.2)\n",
199
+ "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas<3.0,>=1.0->gradio==4.28.3->-r requirements.txt (line 1)) (2023.4)\n",
200
+ "Requirement already satisfied: tzdata>=2022.1 in /usr/local/lib/python3.10/dist-packages (from pandas<3.0,>=1.0->gradio==4.28.3->-r requirements.txt (line 1)) (2024.1)\n",
201
+ "Requirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from pydantic>=2.0->gradio==4.28.3->-r requirements.txt (line 1)) (0.6.0)\n",
202
+ "Requirement already satisfied: pydantic-core==2.18.2 in /usr/local/lib/python3.10/dist-packages (from pydantic>=2.0->gradio==4.28.3->-r requirements.txt (line 1)) (2.18.2)\n",
203
+ "Requirement already satisfied: click>=8.0.0 in /usr/local/lib/python3.10/dist-packages (from typer<1.0,>=0.12->gradio==4.28.3->-r requirements.txt (line 1)) (8.1.7)\n",
204
+ "Collecting shellingham>=1.3.0 (from typer<1.0,>=0.12->gradio==4.28.3->-r requirements.txt (line 1))\n",
205
+ " Downloading shellingham-1.5.4-py2.py3-none-any.whl (9.8 kB)\n",
206
+ "Requirement already satisfied: rich>=10.11.0 in /usr/local/lib/python3.10/dist-packages (from typer<1.0,>=0.12->gradio==4.28.3->-r requirements.txt (line 1)) (13.7.1)\n",
207
+ "Collecting starlette<0.38.0,>=0.37.2 (from fastapi->gradio==4.28.3->-r requirements.txt (line 1))\n",
208
+ " Downloading starlette-0.37.2-py3-none-any.whl (71 kB)\n",
209
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m71.9/71.9 kB\u001b[0m \u001b[31m10.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
210
+ "\u001b[?25hCollecting fastapi-cli>=0.0.2 (from fastapi->gradio==4.28.3->-r requirements.txt (line 1))\n",
211
+ " Downloading fastapi_cli-0.0.3-py3-none-any.whl (9.2 kB)\n",
212
+ "Collecting ujson!=4.0.2,!=4.1.0,!=4.2.0,!=4.3.0,!=5.0.0,!=5.1.0,>=4.0.1 (from fastapi->gradio==4.28.3->-r requirements.txt (line 1))\n",
213
+ " Downloading ujson-5.9.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (53 kB)\n",
214
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m53.2/53.2 kB\u001b[0m \u001b[31m8.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
215
+ "\u001b[?25hCollecting email_validator>=2.0.0 (from fastapi->gradio==4.28.3->-r requirements.txt (line 1))\n",
216
+ " Downloading email_validator-2.1.1-py3-none-any.whl (30 kB)\n",
217
+ "Collecting dnspython>=2.0.0 (from email_validator>=2.0.0->fastapi->gradio==4.28.3->-r requirements.txt (line 1))\n",
218
+ " Downloading dnspython-2.6.1-py3-none-any.whl (307 kB)\n",
219
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m307.7/307.7 kB\u001b[0m \u001b[31m33.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
220
+ "\u001b[?25hRequirement already satisfied: attrs>=22.2.0 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio==4.28.3->-r requirements.txt (line 1)) (23.2.0)\n",
221
+ "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio==4.28.3->-r requirements.txt (line 1)) (2023.12.1)\n",
222
+ "Requirement already satisfied: referencing>=0.28.4 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio==4.28.3->-r requirements.txt (line 1)) (0.35.1)\n",
223
+ "Requirement already satisfied: rpds-py>=0.7.1 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio==4.28.3->-r requirements.txt (line 1)) (0.18.1)\n",
224
+ "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.7->matplotlib~=3.0->gradio==4.28.3->-r requirements.txt (line 1)) (1.16.0)\n",
225
+ "Requirement already satisfied: markdown-it-py>=2.2.0 in /usr/local/lib/python3.10/dist-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio==4.28.3->-r requirements.txt (line 1)) (3.0.0)\n",
226
+ "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /usr/local/lib/python3.10/dist-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio==4.28.3->-r requirements.txt (line 1)) (2.16.1)\n",
227
+ "Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from anyio->httpx>=0.24.1->gradio==4.28.3->-r requirements.txt (line 1)) (1.2.1)\n",
228
+ "Collecting httptools>=0.5.0 (from uvicorn>=0.14.0->gradio==4.28.3->-r requirements.txt (line 1))\n",
229
+ " Downloading httptools-0.6.1-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (341 kB)\n",
230
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m341.4/341.4 kB\u001b[0m \u001b[31m41.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
231
+ "\u001b[?25hCollecting python-dotenv>=0.13 (from uvicorn>=0.14.0->gradio==4.28.3->-r requirements.txt (line 1))\n",
232
+ " Downloading python_dotenv-1.0.1-py3-none-any.whl (19 kB)\n",
233
+ "Collecting uvloop!=0.15.0,!=0.15.1,>=0.14.0 (from uvicorn>=0.14.0->gradio==4.28.3->-r requirements.txt (line 1))\n",
234
+ " Downloading uvloop-0.19.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.4 MB)\n",
235
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.4/3.4 MB\u001b[0m \u001b[31m90.9 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
236
+ "\u001b[?25hCollecting watchfiles>=0.13 (from uvicorn>=0.14.0->gradio==4.28.3->-r requirements.txt (line 1))\n",
237
+ " Downloading watchfiles-0.21.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB)\n",
238
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.3/1.3 MB\u001b[0m \u001b[31m52.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
239
+ "\u001b[?25hRequirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests->huggingface-hub>=0.19.3->gradio==4.28.3->-r requirements.txt (line 1)) (3.3.2)\n",
240
+ "Requirement already satisfied: mdurl~=0.1 in /usr/local/lib/python3.10/dist-packages (from markdown-it-py>=2.2.0->rich>=10.11.0->typer<1.0,>=0.12->gradio==4.28.3->-r requirements.txt (line 1)) (0.1.2)\n",
241
+ "Building wheels for collected packages: ffmpy\n",
242
+ " Building wheel for ffmpy (setup.py) ... \u001b[?25l\u001b[?25hdone\n",
243
+ " Created wheel for ffmpy: filename=ffmpy-0.3.2-py3-none-any.whl size=5584 sha256=abf21335db44f3a266103357a34c5cb3e48ec207ec296943ed61712c11f69b0f\n",
244
+ " Stored in directory: /root/.cache/pip/wheels/bd/65/9a/671fc6dcde07d4418df0c592f8df512b26d7a0029c2a23dd81\n",
245
+ "Successfully built ffmpy\n",
246
+ "Installing collected packages: pydub, ffmpy, websockets, uvloop, ujson, tomlkit, shellingham, semantic-version, ruff, python-multipart, python-dotenv, orjson, opencv-python, opencv-contrib-python, httptools, h11, dnspython, aiofiles, watchfiles, uvicorn, starlette, httpcore, email_validator, typer, httpx, gradio_client, fastapi-cli, fastapi, gradio\n",
247
+ " Attempting uninstall: opencv-python\n",
248
+ " Found existing installation: opencv-python 4.8.0.76\n",
249
+ " Uninstalling opencv-python-4.8.0.76:\n",
250
+ " Successfully uninstalled opencv-python-4.8.0.76\n",
251
+ " Attempting uninstall: opencv-contrib-python\n",
252
+ " Found existing installation: opencv-contrib-python 4.8.0.76\n",
253
+ " Uninstalling opencv-contrib-python-4.8.0.76:\n",
254
+ " Successfully uninstalled opencv-contrib-python-4.8.0.76\n",
255
+ " Attempting uninstall: typer\n",
256
+ " Found existing installation: typer 0.9.4\n",
257
+ " Uninstalling typer-0.9.4:\n",
258
+ " Successfully uninstalled typer-0.9.4\n",
259
+ "\u001b[31mERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n",
260
+ "spacy 3.7.4 requires typer<0.10.0,>=0.3.0, but you have typer 0.12.3 which is incompatible.\n",
261
+ "weasel 0.3.4 requires typer<0.10.0,>=0.3.0, but you have typer 0.12.3 which is incompatible.\u001b[0m\u001b[31m\n",
262
+ "\u001b[0mSuccessfully installed aiofiles-23.2.1 dnspython-2.6.1 email_validator-2.1.1 fastapi-0.111.0 fastapi-cli-0.0.3 ffmpy-0.3.2 gradio-4.28.3 gradio_client-0.16.0 h11-0.14.0 httpcore-1.0.5 httptools-0.6.1 httpx-0.27.0 opencv-contrib-python-4.9.0.80 opencv-python-4.9.0.80 orjson-3.10.3 pydub-0.25.1 python-dotenv-1.0.1 python-multipart-0.0.9 ruff-0.4.4 semantic-version-2.10.0 shellingham-1.5.4 starlette-0.37.2 tomlkit-0.12.0 typer-0.12.3 ujson-5.9.0 uvicorn-0.29.0 uvloop-0.19.0 watchfiles-0.21.0 websockets-11.0.3\n"
263
+ ]
264
+ }
265
+ ],
266
+ "source": [
267
+ "!pip install -r requirements.txt"
268
+ ]
269
+ },
270
+ {
271
+ "cell_type": "markdown",
272
+ "source": [
273
+ "# 実行"
274
+ ],
275
+ "metadata": {
276
+ "id": "LUcp4xt2fJU9"
277
+ }
278
+ },
279
+ {
280
+ "cell_type": "code",
281
+ "source": [
282
+ "!python app.py --share True"
283
+ ],
284
+ "metadata": {
285
+ "colab": {
286
+ "base_uri": "https://localhost:8080/"
287
+ },
288
+ "id": "J3kKmi6Rd95n",
289
+ "outputId": "d06135be-5c00-4b68-abba-6606f415ccce"
290
+ },
291
+ "execution_count": 5,
292
+ "outputs": [
293
+ {
294
+ "output_type": "stream",
295
+ "name": "stdout",
296
+ "text": [
297
+ "2024-05-11 12:13:31,862#アプリ起動中\n",
298
+ "2024-05-11 12:13:36,775#アプリ起動完了(4.912s)\n",
299
+ "Running on local URL: http://127.0.0.1:9999\n",
300
+ "Running on public URL: https://90361c40461e1540a1.gradio.live\n",
301
+ "\n",
302
+ "This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)\n",
303
+ "Keyboard interruption in main thread... closing server.\n",
304
+ "Killing tunnel 127.0.0.1:9999 <> https://90361c40461e1540a1.gradio.live\n"
305
+ ]
306
+ }
307
+ ]
308
+ }
309
+ ]
310
+ }
requirements.txt CHANGED
@@ -1,75 +1,4 @@
1
- aiofiles==23.2.1
2
- altair==5.3.0
3
- annotated-types==0.6.0
4
- anyio==4.3.0
5
- attrs==23.2.0
6
- certifi==2024.2.2
7
- charset-normalizer==3.3.2
8
- click==8.1.7
9
- colorama==0.4.6
10
- contourpy==1.2.1
11
- cycler==0.12.1
12
- dnspython==2.6.1
13
- email_validator==2.1.1
14
- exceptiongroup==1.2.1
15
- fastapi==0.111.0
16
- fastapi-cli==0.0.2
17
- ffmpy==0.3.2
18
- filelock==3.14.0
19
- fonttools==4.51.0
20
- fsspec==2024.3.1
21
  gradio==4.28.3
22
  gradio_client==0.16.0
23
- h11==0.14.0
24
- httpcore==1.0.5
25
- httptools==0.6.1
26
- httpx==0.27.0
27
- huggingface-hub==0.23.0
28
- idna==3.7
29
- importlib_resources==6.4.0
30
- Jinja2==3.1.3
31
- jsonschema==4.22.0
32
- jsonschema-specifications==2023.12.1
33
- kiwisolver==1.4.5
34
- markdown-it-py==3.0.0
35
- MarkupSafe==2.1.5
36
- matplotlib==3.8.4
37
- mdurl==0.1.2
38
- numpy==1.26.4
39
  opencv-python==4.9.0.80
40
  opencv-contrib-python==4.9.0.80
41
- orjson==3.10.2
42
- packaging==24.0
43
- pandas==2.2.2
44
- pillow==10.3.0
45
- pydantic==2.7.1
46
- pydantic_core==2.18.2
47
- pydub==0.25.1
48
- Pygments==2.17.2
49
- pyparsing==3.1.2
50
- python-dateutil==2.9.0.post0
51
- python-dotenv==1.0.1
52
- python-multipart==0.0.9
53
- pytz==2024.1
54
- PyYAML==6.0.1
55
- referencing==0.35.1
56
- requests==2.31.0
57
- rich==13.7.1
58
- rpds-py==0.18.0
59
- ruff==0.4.2
60
- semantic-version==2.10.0
61
- shellingham==1.5.4
62
- six==1.16.0
63
- sniffio==1.3.1
64
- starlette==0.37.2
65
- tomlkit==0.12.0
66
- toolz==0.12.1
67
- tqdm==4.66.4
68
- typer==0.12.3
69
- typing_extensions==4.11.0
70
- tzdata==2024.1
71
- ujson==5.9.0
72
- urllib3==2.2.1
73
- uvicorn==0.29.0
74
- watchfiles==0.21.0
75
- websockets==11.0.3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  gradio==4.28.3
2
  gradio_client==0.16.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  opencv-python==4.9.0.80
4
  opencv-contrib-python==4.9.0.80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
run.bat CHANGED
@@ -2,6 +2,6 @@
2
 
3
  cd %~dp0
4
  call venv\Scripts\activate
5
- python src\launch.py --server_port 9999
6
 
7
  TIMEOUT /T 10
 
2
 
3
  cd %~dp0
4
  call venv\Scripts\activate
5
+ python app.py --server_port 9999
6
 
7
  TIMEOUT /T 10
src/app.py DELETED
@@ -1,99 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- """
3
- SaliencyMapDemo
4
- """
5
- import argparse
6
- from datetime import datetime
7
- import sys
8
-
9
- import cv2
10
- import gradio as gr
11
- import numpy as np
12
-
13
- import utils
14
-
15
- PROGRAM_NAME = 'SaliencyMapDemo'
16
- __version__ = utils.get_package_version()
17
-
18
- def compute_saliency(image: np.ndarray):
19
- """
20
- 入力画像から顕著性マップを作成しJET画像を返します。
21
- Parameters
22
- ----------
23
- param1 : np.ndarray
24
- 入力画像
25
-
26
- Returns
27
- -------
28
- np.ndarray
29
- カラーマップのJET画像
30
- """
31
- # OpenCVのsaliencyを作成
32
- saliency = cv2.saliency.StaticSaliencySpectralResidual_create()
33
- # 画像の顕著性を計算
34
- success, saliencyMap = saliency.computeSaliency(image)
35
-
36
- if success:
37
- # 顕著性マップをカラーマップに変換
38
- saliencyMap = (saliencyMap * 255).astype("uint8")
39
- saliencyMap = cv2.applyColorMap(saliencyMap, cv2.COLORMAP_JET)
40
-
41
- #overlay = saliencyMap
42
- # 元の画像とカラーマップを重ね合わせ
43
- overlay = cv2.addWeighted(image, 0.5, saliencyMap, 0.5, 0)
44
-
45
- return overlay
46
- else:
47
- return image # エラーが発生した場合は元の画像を返す
48
-
49
- def run(args: argparse.Namespace, watch: utils.Stopwatch) -> None:
50
- """
51
- アプリの画面を作成し、Gradioサービスを起動します。
52
- ----------
53
- param1 : argparse.Namespace
54
- コマンドライン引数
55
- param2 : utils.Stopwatch
56
- 起動したスタート時間
57
- """
58
- # analytics_enabled=False
59
- # https://github.com/gradio-app/gradio/issues/4226
60
- with gr.Blocks(analytics_enabled=False, \
61
- title=f"{PROGRAM_NAME} {__version__}", \
62
- head="""
63
- <meta name="format-detection" content="telephone=no">
64
- <meta name="robots" content="noindex, nofollow, noarchive">
65
- <meta name="referrer" content="no-referrer" />
66
- """) as demo:
67
-
68
- gr.Markdown(
69
- """
70
- # Saliency Map demo.
71
- 1. inputタブで画像を選択します。
72
- 2. Submitボタンを押します。
73
- ※画像は外部送信していません。ローカルで処理が完結します。
74
- 3. 結果は、overlayタブに表示します。
75
- """)
76
-
77
- submit_button = gr.Button("submit")
78
-
79
- with gr.Row():
80
- with gr.Tab("input"):
81
- image_input = gr.Image()
82
- with gr.Tab("overlay"):
83
- image_overlay = gr.Image(interactive=False)
84
-
85
-
86
- submit_button.click(compute_saliency, inputs=image_input, outputs=image_overlay)
87
-
88
- gr.Markdown(
89
- f"""
90
- Python {sys.version}
91
- App {__version__}
92
- """)
93
-
94
- demo.queue(default_concurrency_limit=5)
95
-
96
- print(f"{datetime.now()}:アプリ起動完了({watch.stop():.3f}s)")
97
-
98
- # https://www.gradio.app/docs/gradio/blocks#blocks-launch
99
- demo.launch(max_file_size=args.max_file_size, server_port=args.server_port, inbrowser=True, share=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/launch.py DELETED
@@ -1,28 +0,0 @@
1
- # -*- coding: utf-8 -*-
2
- """
3
- SaliencyMapDemo
4
- """
5
- import argparse
6
- from datetime import datetime
7
-
8
- from utils import get_package_version, Stopwatch
9
-
10
- def main():
11
- """
12
- エントリーポイント
13
- コマンドライン引数の解析を行います
14
- """
15
- print(f"{datetime.now()}:アプリ起動中")
16
- watch = Stopwatch.startNew()
17
-
18
- import app
19
-
20
- parser = argparse.ArgumentParser(prog=app.PROGRAM_NAME, description="SaliencyMapDemo")
21
- parser.add_argument('--server_port', type=int, default=9999, help="Gradio server port")
22
- parser.add_argument('--max_file_size', type=int, default=20 * 1024 * 1024, help="Gradio max file size")
23
- parser.add_argument('--version', action='version', version=f'%(prog)s {get_package_version()}')
24
-
25
- app.run(parser.parse_args(), watch)
26
-
27
- if __name__ == "__main__":
28
- main()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
src/myapp.py ADDED
@@ -0,0 +1,134 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ from typing import Literal
3
+
4
+ import argparse
5
+ from datetime import datetime
6
+ import sys
7
+
8
+ import gradio as gr
9
+ import numpy as np
10
+
11
+ import src.utils as utils
12
+ from src.saliency import SaliencyMap, convertColorMap
13
+ from src.reporter import get_current_reporter
14
+
15
+ PROGRAM_NAME = 'SaliencyMapDemo'
16
+ __version__ = utils.get_package_version()
17
+ log = get_current_reporter()
18
+
19
+ def jetTab_Selected(image: np.ndarray):
20
+ #print(f"{datetime.now()}#jet")
21
+ saliency = SaliencyMap("SpectralResidual")
22
+ success, saliencyMap = saliency.computeSaliency(image)
23
+ retval = convertColorMap(image, saliencyMap, "jet")
24
+ #print(f"{datetime.now()}#jet")
25
+
26
+ return retval
27
+
28
+ def hotTab_Selected(image: np.ndarray):
29
+ #print(f"{datetime.now()}#hot")
30
+ saliency = SaliencyMap("SpectralResidual")
31
+ success, saliencyMap = saliency.computeSaliency(image)
32
+ retval = convertColorMap(image, saliencyMap, "turbo")
33
+ #print(f"{datetime.now()}#hot")
34
+
35
+ return retval
36
+
37
+ def submit_Clicked(image: np.ndarray, algorithm: str):
38
+ """
39
+ 入力画像を元に顕著マップを計算します。
40
+
41
+ Parameters:
42
+ image: 入力画像
43
+ str: 顕著性マップのアルゴリズム
44
+ Returns:
45
+ np.ndarray: JET画像
46
+ np.ndarray: HOT画像
47
+ """
48
+ #log.info(f"#submit_Clicked")
49
+ watch = utils.Stopwatch.startNew()
50
+
51
+ saliency = SaliencyMap(algorithm)
52
+ success, saliencyMap = saliency.computeSaliency(image)
53
+ #log.info(f"#SaliencyMap computeSaliency()")
54
+
55
+ if not success:
56
+ return image, image # エラーが発生した場合は入力画像を返します。
57
+
58
+ #log.info(f"#jet")
59
+ jet = convertColorMap(image, saliencyMap, "jet")
60
+ #jet = None
61
+ #log.info(f"#hot")
62
+ hot = convertColorMap(image, saliencyMap, "hot")
63
+
64
+ saliency = None
65
+ #log.info(f"#submit_Clicked End{watch.stop():.3f}")
66
+
67
+ return jet, hot
68
+
69
+ def runApp(args: argparse.Namespace, watch: utils.Stopwatch) -> None:
70
+ """
71
+ アプリの画面を作成し、Gradioサービスを起動します。
72
+
73
+ Parameters:
74
+ args: コマンドライン引数
75
+ watch: 起動したスタート時間
76
+ """
77
+ # analytics_enabled=False
78
+ # https://github.com/gradio-app/gradio/issues/4226
79
+ with gr.Blocks(analytics_enabled=False, \
80
+ title=f"{PROGRAM_NAME} {__version__}", \
81
+ head="""
82
+ <meta name="format-detection" content="telephone=no">
83
+ <meta name="robots" content="noindex, nofollow, noarchive">
84
+ <meta name="referrer" content="no-referrer" />
85
+ """) as demo:
86
+
87
+ gr.Markdown(
88
+ """
89
+ # Saliency Map demo.
90
+ """)
91
+ with gr.Accordion("取り扱い説明書", open=False):
92
+ gr.Markdown(
93
+ """
94
+ 1. inputタブで画像を選択します。
95
+ 2. Submitボタンを押します。
96
+ ※画像は外部送信していません。ローカルで処理が完結します。
97
+ 3. 結果は、JETタブとHOTタブに表示します。
98
+ """)
99
+
100
+ algorithmType = gr.Radio(["SpectralResidual", "FineGrained"], label="Saliency", value="SpectralResidual", interactive=True)
101
+
102
+ submit_button = gr.Button("submit")
103
+
104
+ with gr.Row():
105
+ with gr.Tab("input", id="input"):
106
+
107
+ image_input = gr.Image(sources = ["upload", "clipboard"], interactive=True)
108
+ with gr.Tab("overlay(JET)"):
109
+ image_overlay_jet = gr.Image(interactive=False)
110
+ #tab_jet.select(jetTab_Selected, inputs=[image_input], outputs=image_overlay_jet)
111
+ with gr.Tab("overlay(HOT)"):
112
+ image_overlay_hot = gr.Image(interactive=False)
113
+ #tab_hot.select(hotTab_Selected, inputs=[image_input], outputs=image_overlay_hot, api_name=False)
114
+
115
+ submit_button.click(submit_Clicked, inputs=[image_input, algorithmType], outputs=[image_overlay_jet, image_overlay_hot])
116
+
117
+ gr.Markdown(
118
+ f"""
119
+ Python {sys.version}
120
+ App {__version__}
121
+ """)
122
+
123
+ demo.queue(default_concurrency_limit=5)
124
+
125
+ log.info(f"#アプリ起動完了({watch.stop():.3f}s)")
126
+ # https://www.gradio.app/docs/gradio/blocks#blocks-launch
127
+
128
+ demo.launch(
129
+ max_file_size=args.max_file_size,
130
+ server_port=args.server_port,
131
+ inbrowser=args.inbrowser,
132
+ share=args.share,
133
+ )
134
+
src/reporter.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Reporter
4
+ ログハンドラーが重複登録されるのを防ぐために1箇所で生成してログハンドラーを返します。
5
+ Example:
6
+ from reporter import get_current_reporter
7
+
8
+ logger = get_current_reporter()
9
+ logger.info("message");
10
+ """
11
+ from logging import Logger, getLogger, Formatter, StreamHandler
12
+ from logging import DEBUG
13
+
14
+ _reporters = []
15
+
16
+ def get_current_reporter() -> Logger:
17
+ return _reporters[-1]
18
+
19
+ def __make_reporter(name: str='SaliencyMapDemo') -> None:
20
+ """
21
+ ログハンドラーを生成します。
22
+ @see https://docs.python.jp/3/howto/logging-cookbook.html#logging-to-a-single-file-from-multiple-processes
23
+
24
+ Parameters:
25
+ name: アプリ名
26
+ """
27
+ handler = StreamHandler() # コンソールに出力します。
28
+ formatter = Formatter('%(asctime)s%(message)s')
29
+ handler.setFormatter(formatter)
30
+ handler.setLevel(DEBUG)
31
+
32
+ logger = getLogger(name)
33
+ logger.setLevel(DEBUG)
34
+ logger.addHandler(handler)
35
+ _reporters.append(logger)
36
+
37
+ __make_reporter()
38
+
39
+ def main():
40
+ """
41
+ Entry Point
42
+ """
43
+ assert len(_reporters) == 1
44
+
45
+ logger = get_current_reporter()
46
+ logger.debug("main")
47
+
48
+ if __name__ == "__main__":
49
+ main()
src/saliency.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ from typing import Literal
3
+
4
+ import numpy as np
5
+ import cv2
6
+
7
+
8
+ class SaliencyMap:
9
+ """
10
+ SaliencyMap 顕著性マップを計算するクラスです。
11
+ Example:
12
+ from lib.saliency import SaliencyMap
13
+
14
+ saliency = SaliencyMap("SpectralResidual")
15
+ success, saliencyMap = saliency.computeSaliency(image)
16
+ """
17
+ def __init__(
18
+ self,
19
+ algorithm: Literal["SpectralResidual", "FineGrained"] = "SpectralResidual",
20
+ ):
21
+ self.algorithm = algorithm
22
+ # OpenCVのsaliencyを作成します。
23
+ if algorithm == "SpectralResidual":
24
+ self.saliency = cv2.saliency.StaticSaliencySpectralResidual_create()
25
+ else:
26
+ self.saliency = cv2.saliency.StaticSaliencyFineGrained_create()
27
+
28
+
29
+ def computeSaliency(self, image: np.ndarray):
30
+ """
31
+ 入力画像から顕著性マップを作成します。
32
+
33
+ Parameters:
34
+ image: 入力画像
35
+
36
+ Returns:
37
+ bool:
38
+ true: SaliencyMap computed, false:NG
39
+ np.ndarray: 顕著性マップ
40
+ """
41
+ # 画像の顕著性を計算します。
42
+ return self.saliency.computeSaliency(image)
43
+
44
+ def convertColorMap(
45
+ image: np.ndarray,
46
+ saliencyMap: np.ndarray,
47
+ colormap_name: Literal["jet", "hot", "turbo"] = "jet"):
48
+ """
49
+ 顕著性マップをカラーマップに変換後に、入力画像に重ね合わせします。
50
+
51
+ Parameters:
52
+ image: 入力画像
53
+ saliencyMap: 顕著性マップ
54
+ colormap_name: カラーマップの種類
55
+
56
+ Returns:
57
+ np.ndarray: 重ね合わせた画像(RGBA形式)
58
+ """
59
+ colormaps = {"jet": cv2.COLORMAP_JET, "hot": cv2.COLORMAP_HOT, "turbo": cv2.COLORMAP_TURBO}
60
+ if colormap_name not in colormaps:
61
+ raise ValueError(colormap_name)
62
+
63
+ # 顕著性マップをカラーマップに変換
64
+ saliencyMap = (saliencyMap * 255).astype("uint8")
65
+ saliencyMap = cv2.applyColorMap(saliencyMap, colormaps[colormap_name])
66
+ #return saliencyMap
67
+ # 入力画像とカラーマップを重ね合わせ
68
+ overlay = cv2.addWeighted(image, 0.5, saliencyMap, 0.5, 0)
69
+ #return overlay
70
+
71
+ return cv2.cvtColor(overlay, cv2.COLOR_BGR2RGBA)
src/utils.py CHANGED
@@ -2,11 +2,17 @@
2
  import time
3
 
4
  def get_package_version() -> str:
5
- return '0.0.2'
6
 
7
  class Stopwatch:
8
  """
9
  Stopwatch 経過時間を計測するためのクラスです。
 
 
 
 
 
 
10
  """
11
 
12
  def __init__(self):
@@ -31,4 +37,3 @@ class Stopwatch:
31
  end_time = time.perf_counter()
32
  self._elapsed = end_time - self._start_time
33
  return self._elapsed
34
-
 
2
  import time
3
 
4
  def get_package_version() -> str:
5
+ return '0.0.3'
6
 
7
  class Stopwatch:
8
  """
9
  Stopwatch 経過時間を計測するためのクラスです。
10
+ Example:
11
+ from utils import Stopwatch
12
+
13
+ watch = Stopwatch.startNew()
14
+ # 計測する処理
15
+ print(f"{watch.stop():.3f}")
16
  """
17
 
18
  def __init__(self):
 
37
  end_time = time.perf_counter()
38
  self._elapsed = end_time - self._start_time
39
  return self._elapsed
 
test/__init__.py ADDED
File without changes
test/test_create_grayscale_gradation.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ import unittest
3
+
4
+ import numpy as np
5
+ from PIL import Image
6
+
7
+ class TestGrayscale(unittest.TestCase):
8
+ pass
9
+
10
+
11
+ def main():
12
+ # グラデーションのサイズを定義します
13
+ width = 256
14
+ height = 256
15
+
16
+ # numpyを使用してグレースケールのグラデーションを作成します
17
+ gradient = np.linspace(0, 255, width, dtype=np.uint8)
18
+
19
+ # 2次元のグラデーションを作成します
20
+ gradient = np.tile(gradient, (height, 1))
21
+
22
+ # PIL Imageオブジェクトを作成します
23
+ image = Image.fromarray(gradient, mode='L')
24
+
25
+ # 画像を表示します
26
+ image.show()
27
+
28
+ if __name__ == "__main__":
29
+ #main()
30
+ unittest.main()
test/test_files/grayscale_256x256.png ADDED
test/test_files/grayscale_256x256.webp ADDED
test/testrun.bat ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ @echo on
2
+
3
+ cd %~dp0
4
+ call ..\venv\Scripts\activate
5
+ python -m unittest -v test_create_grayscale_gradation.py
6
+
7
+ TIMEOUT /T 30