質問編集履歴
4
直したコードの引数が直されておりませんでした、申し訳ございません。
title
CHANGED
File without changes
|
body
CHANGED
@@ -87,7 +87,7 @@
|
|
87
87
|
plt.imshow(img)
|
88
88
|
plt.show()
|
89
89
|
|
90
|
-
def changeToGray( number: int,
|
90
|
+
def changeToGray( number: int, length: int ):
|
91
91
|
"""
|
92
92
|
並列化する処理
|
93
93
|
@param number (int) : 画像の処理対象範囲の先頭の添字
|
@@ -105,7 +105,7 @@
|
|
105
105
|
pixel[2] = gray
|
106
106
|
return number, part_height
|
107
107
|
|
108
|
-
def mulchProcess(useCPU: int):
|
108
|
+
def mulchProcess(useCPU: int, step: int):
|
109
109
|
"""
|
110
110
|
マルチコアでプロセスを生成して実行させる処理
|
111
111
|
@param useCPU (int) : 使用するCPUのコア数
|
@@ -113,7 +113,7 @@
|
|
113
113
|
"""
|
114
114
|
index_list = [ i for i in range(0, len(img), step) if i < len(img) ]
|
115
115
|
with concurrent.futures.ProcessPoolExecutor(max_workers=useCPU) as executer:
|
116
|
-
fs = [ executer.submit(
|
116
|
+
fs = [ executer.submit(changeToGray, i, step) for i in index_list ]
|
117
117
|
for future in concurrent.futures.as_completed(fs):
|
118
118
|
line_number = future.result()[0]
|
119
119
|
part_height = future.result()[1]
|
3
よくみたけどあの人の言いたいことがわからない、、、
title
CHANGED
File without changes
|
body
CHANGED
@@ -95,7 +95,6 @@
|
|
95
95
|
@return number (int) : 画像の処理対象範囲の先頭の添字
|
96
96
|
@return part_height (int) : 処理後の画像の配列
|
97
97
|
"""
|
98
|
-
start = time.time()
|
99
98
|
endPioint = number + length if number + length < len(img) else len(img) - 1
|
100
99
|
part_height = img[ number : endPioint-1 ]
|
101
100
|
for width in part_height:
|
2
私なりの見解と実行時間と使用画像を追加しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,6 +4,8 @@
|
|
4
4
|
|
5
5
|
ですので、何処がボトルネックになっているかご指摘と改善出来るならアドバイス頂けるとありがたいです。
|
6
6
|
|
7
|
+
個人的には、並列化した時の通信時間よりforの方が時間がかかっている感じがするのでこのような結果になったのではないかなぁと推測しております。
|
8
|
+
|
7
9
|
### 元のソースコード
|
8
10
|
```Python3
|
9
11
|
import concurrent.futures
|
@@ -134,4 +136,9 @@
|
|
134
136
|
MacBook Pro (15-inch, 2016)
|
135
137
|
プロセッサ : 2.6 GHz Intel Core i7 ( 4コア8スレッド )
|
136
138
|
メモリ : 16 GB 2133 MHz LPDDR3
|
137
|
-
Python 3.6.4
|
139
|
+
Python 3.6.4
|
140
|
+
|
141
|
+
[実行時間]
|
142
|
+
使用画像 : 5000px*5025px (15.1MB)
|
143
|
+
修正前のコード : 44.79758310317993秒
|
144
|
+
修正後のコード : 45.401297092437744秒
|
1
画像読み込みのところを編集しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
import numpy as np
|
12
12
|
import cv2, sys, os
|
13
13
|
|
14
|
-
img =
|
14
|
+
img = cv2.cvtColor(cv2.imread(sys.argv[1]), cv2.COLOR_BGR2RGB)
|
15
15
|
useCPU = 1
|
16
16
|
|
17
17
|
def main():
|
@@ -66,7 +66,7 @@
|
|
66
66
|
import numpy as np
|
67
67
|
import cv2, sys, os
|
68
68
|
|
69
|
-
img =
|
69
|
+
img = cv2.cvtColor(cv2.imread(sys.argv[1]), cv2.COLOR_BGR2RGB)
|
70
70
|
useCPU = 1
|
71
71
|
step = 1
|
72
72
|
|