faceboxesのbatch処理を追加#4
Merged
Merged
Conversation
yujidn
commented
Dec 8, 2021
|
|
||
| im_height, im_width, im_ch = images[0].shape | ||
| scale = torch.Tensor([im_width, im_height, im_width, im_height]) | ||
| images = np.array(images).reshape(len(images), im_height, im_width, im_ch) |
Author
There was a problem hiding this comment.
リスト内部の画像サイズが違う場合はここでValueErrorが発生する
yujidn
commented
Dec 8, 2021
| image_inds = thres_tuple[0].data.cpu().numpy() | ||
| boxes_inds = thres_tuple[1].data.cpu().numpy() | ||
|
|
||
| # ここgpu化しなくても処理時間が支配的ではないのでcpuでやる |
Author
There was a problem hiding this comment.
1000枚画像相手だと全体が1000ms ~ 1500msに対して30~50ms程度だった
(gpuでやれるならgpuでやりたい
yujidn
commented
Dec 10, 2021
| # 以降gpu上の画像は使わないので解放する | ||
| # 速度に影響なさそうなのでループごとに実行 | ||
| del imgs | ||
| torch.cuda.empty_cache() |
Author
There was a problem hiding this comment.
https://pytorch.org/docs/stable/notes/cuda.html#memory-management
memory_allocatedとmemory_reserved があり
del tensor -> 該当tensorが使っていた分のメモリが解放されてmemory_allocatedが増える
empty_cache -> pytorchがreservedしているmemoryのうち使っていない分が解放される
| model.load_state_dict(pretrained_dict, strict=False) | ||
| return model | ||
|
|
||
| @torch.no_grad() |
Author
There was a problem hiding this comment.
https://pytorch.org/docs/stable/generated/torch.no_grad.html
with句 または デコレータをつけることで内部の勾配計算をなくしてメモリ節約
| new_result = (confs, [b * ratios for b in boxes]) | ||
| new_results.append(new_result) | ||
|
|
||
| return new_results |
Author
There was a problem hiding this comment.
実行時にリサイズし、結果をオリジナルスケールに直す処理を追加
- オリジナル画像 -> get_faceboxes
- オリジナル画像s -> get_batch_faceboxes_with_resize -> resized_images -> get_batch_faceboxes
この2パターンを比較すると、最大50ピクセルほどずれる(実装ミスあるかも
Author
There was a problem hiding this comment.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

batch処理を追加
1000枚あたりの処理時間が、
get_faceboxes(): 12.5s
get_batch_faceboxes(): 1.67s
となる(約10分の1
動作確認
各画像での
ことを確認している