質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
並列処理

複数の計算が同時に実行される手法

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Ubuntu

Ubuntuは、Debian GNU/Linuxを基盤としたフリーのオペレーティングシステムです。

Q&A

解決済

1回答

3476閲覧

ThreadPoolだと動くのにProcessPoolだと動かない

reiya_123

総合スコア57

並列処理

複数の計算が同時に実行される手法

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Ubuntu

Ubuntuは、Debian GNU/Linuxを基盤としたフリーのオペレーティングシステムです。

0グッド

0クリップ

投稿2021/12/06 09:19

編集2021/12/06 09:21

前提・実現したいこと

現在、物体認識しその認識をもとに解析をしています。
また、解析をしている最中でも物体認識を止めたくないため並列処理を行おうとしています。
流れとしては、はじめは物体認識だけの関数だけ実行し、認識したら解析する関数も起動し並列処理をし、解析が終わったらまた、物体認識だけにしていきたいと考えています。

発生している問題・エラーメッセージ

発生している問題ですが並列処理を行う際、ProcessPoolExecutorを使っていますがm.process関数内の「print("Network successfully loaded")」までは実行できますが「print("config前")」までは実行できていません。よって、main関数内のexecutor.submit(m.process)がうまくいってないように思えます。
また、m.processを単体では動く状態で、ThreadPoolExecutorを使っても動く状態となっています。
申し訳ございませんがなぜProcessPoolExecutorを使うとm.processがうまく起動できないのかご教示いただけないでしょうか。
宜しくおねがいいたします。

main関数

def main(): if os.path.exists(count_image_path): print("count_image_pathが存在するので削除します") os.remove(count_image_path) if os.path.exists(text_reading_image_path): print("text_reading_image_pathが存在するので削除します") os.remove(text_reading_image_path) m = Main() executor = concurrent.futures.ProcessPoolExecutor(max_workers=2)    #executor = concurrent.futures.ThreadPoolExecutor(max_workers=2)に変えると起動する executor.submit(m.process) r_running = False while True: # プロセスrが動作していなくて、プロセスmの情報ができたらプロセスrを起動 if not r_running and os.path.exists(count_image_path)== True: r = Run_image() executor.submit(r.run) r_running = True # プロセスrが終了したら、フラグを落す。 if os.path.exists(text_reading_image_path): r_running = False

###m.processの部分

class Main: def __init__(self): self.speed = 1 self.j = 0 def process(self): # Defining world dimensions world_size = (720, 900) image_path ="/program/main/resize_map.jpg" image = cv2.imread(image_path)      #start地点 agent = Agent(Position(720,75), scan_radius=0.60, possible_moves=30) #goal地点 goal = Goal(Position(588,218), sigma=math.sqrt(world_size[0]**2 + world_size[1]**2)) agent.draw(image) goal.draw(image) cv2.imshow('Output', image) cv2.moveWindow('Output', 1950, 100) cv2.waitKey(100) #ポテンシャル法による画像に点描写するプログラム navi = 0 args = self.arg_parse() confidence = float(args.confidence) nms_thesh = float(args.nms_thresh) CUDA = torch.cuda.is_available() num_classes = 80 print("Loading network.....") model = Darknet(args.cfgfile) model.load_weights(args.weightsfile) print("Network successfully loaded") if CUDA: model.cuda()      print("config前") # ストリーム(Color/Depth)の設定 config = rs.config() #realsenseでbagファイルを保存しそれを再生、現状、ProcessPoolだと再生されない config.enable_device_from_file('/media/limlab/48A9A14C31288186/jn.bag',repeat_playback=False) config.enable_stream(rs.stream.color, 640, 480, rs.format.bgr8, 30) config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30) ストリーミング開始 pipeline = rs.pipeline() profile = pipeline.start(config) align = rs.align(rs.stream.color) print("進みます") playsound('/program/voice/go_straight.mp3') try: #もしゴールまで0.3以上あればゴールに近づいていく while Position.calculate_distance(agent.position, goal.position) > 0.3: try: realsenseの設定 frames = pipeline.wait_for_frames() color_frame = frames.get_color_frame() depth_frame = frames.get_depth_frame() if not depth_frame or not color_frame: continue frames = align.process(frames) profile = frames.get_profile() #画像データに変換 color_image = np.asanyarray(color_frame.get_data()) depth_color_frame = rs.colorizer().colorize(depth_frame) depth_color_image = np.asanyarray(depth_color_frame.get_data())

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

解決法とはなりませんがgpuの性能をあげたところ動くようになりました。

投稿2021/12/10 08:59

reiya_123

総合スコア57

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問