Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Goで並⾏処理を⽤いた 画像処理を実装した話|株式会社Newbees
Search
Newbees Inc
June 05, 2023
Programming
330
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Goで並⾏処理を⽤いた 画像処理を実装した話|株式会社Newbees
2023年6月1日に開催された「Go Conference2023」
登壇した際の資料となります。
Newbees Inc
June 05, 2023
More Decks by Newbees Inc
See All by Newbees Inc
Matching theory-based recommender systems in online dating
newbees
0
150
Siamese neural networks in recommendation
newbees
0
140
Newbees採用資料(2026.04更新)
newbees
2
59k
Other Decks in Programming
See All in Programming
SalesForceを内製化!? ~ HR事業を支える顧客管理基盤のインフラを大公開 ~
oku053
0
170
すこし踏み込む CancellationToken
htkym
2
1.7k
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
23
23k
ソニーのクラウド共通基盤の変遷とAI時代の開発スタイルに合わせた進化 / The Journey of Sony’s Common Cloud Platform and Its Evolution for AI-Native Development
kenjiyoneyama
0
260
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
990
作れる、でも消せるか?──安全に「枯らして消す」機能削除術 / Drain, Then Delete
chobishiba
2
370
カツオ、ご期待ください
suneo3476
0
180
最近”作らせてる” ローカルAIアプリの話
akit37
0
460
IBM Bob でAI駆動開発『QC-Playbook』
ichirokano2
0
110
IBM Bob Dojo #1 仕様駆動開発入門
oniak3ibm
PRO
0
380
UnityでSystem.Net.WebSocketsなWebSocketサーバが動かないのでUnity Monoのコードを覗いてみた / about implementing websocket server with unity mono
drumath2237
1
590
Domain-Driven Transformation
hschwentner
2
2.3k
Featured
See All Featured
Rebuilding a faster, lazier Slack
samanthasiow
85
9.7k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
The Curse of the Amulet
leimatthew05
3
15k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
300
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
280
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
A Modern Web Designer's Workflow
chriscoyier
699
190k
Deep Space Network (abreviated)
tonyrice
0
370
Scaling GitHub
holman
464
140k
A Tale of Four Properties
chriscoyier
163
24k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
300
Transcript
Goで並⾏処理を⽤いた 画像処理を実装した話 Yuya Hiramatsu Go Conference 2023 (2023-06-02)
⾃⼰紹介 株式会社Newbees 所 属 バックエンド, iOS, 研究開発(画像解析, 機械学習) 担 当
Yuya Hiramatsu 名 前 Goでは主に画像解析の実装経験がある
背景 要件:ユーザーから受信した⾝分証画像の番号をモザイク加⼯する OCRにより画像内から検出された⽂字の位置情報を元に 任意の4点を結ぶ四⾓形内をモザイク加⼯する処理を実装 保険証の番号をモザイク加⼯した例
背景 ⽬的の画像処理ライブラリがなかったため独⾃で実装する必要があった 並⾏処理を⽤いて処理時間の⾼速化を図る 保険証の番号をモザイク加⼯した例
アルゴリズム 1. ⽂字を囲う四⾓形内を複数のブロックに区切る 2. 各ブロック内の平均ピクセル値を求める 3. 各ブロック内の全てのピクセルを2.で求めた平均ピクセル値に更新する
アルゴリズム 1. ⽂字を囲う四⾓形内を複数のブロックに区切る 2. 各ブロック内の平均ピクセル値を求める 3. 各ブロック内の全てのピクセルを2.で求めた平均ピクセル値に更新する
アルゴリズム 各ブロックの処理を複数のgoroutineで⾏い並⾏処理化する goroutine A goroutine B goroutine C goroutine D
4つのgoroutineで処理する例
// goroutine起動 // 起動するgoroutine数 // i番⽬のgoroutineが処理するブロックの範囲 // 全てのgoroutineの処理が終わるまで待機 // (x,
y)番地のブロックのマスキング処理 並⾏処理部分のソースコード
実験環境 l MacBook Pro M1(2021) • メモリ16GB, 8スレッド l 画像:スマホで撮影した⾝分証
• サイズ:3024×4032 [pixel] • マスキング対象箇所:5箇所 l ベンチマーク testingパッケージのBenchmark関数 対象画像の例 (⾚枠がマスキング対象)
ベンチマーク 並⾏処理化前 並⾏処理化後 平均処理時間 割り当てられた メモリ量 割り当て回数 実⾏回数 およそ3倍速くなった
余談:並⾏処理化に伴ったアルゴリズムの変更 従来⼿法:並⾏処理化が難しく計算コストが⾼い 四⾓形内のピクセルを抽出する際に端から連続的に操作する必要があり 複数スレッドでの処理分割が困難だった 2度⽬に境界線に当たったら 内部判定終了 端から順番にピクセルを⾒ていき 初めて境界線に当たったら内部判定開始
余談:並⾏処理化に伴ったアルゴリズムの変更 各ピクセルごとに独⽴して処理できるアルゴリズムに改修 サイズが⼤きい画像において処理時間が平均3秒改善された
考察とまとめ l 画像処理の並⾏処理化により処理速度が向上 • 画像処理は並⾏処理可能な計算が多いため並⾏処理に向いている • goroutineを⽤いる実装の⼿軽さを実感 l アルゴリズムの変更により処理速度が⼤幅に向上 •
処理を⾼速化したい場合はまず初めにアルゴリズムを⾒直すことが 重要
Engineer、Designer、Director、QA、HRGA Newbeesでは全ての部署で⼀緒に働くメンバーを募集中です! We Are Hiring! Newbees 採⽤情報 https://newbees.jp/career/