์ผ | ์ | ํ | ์ | ๋ชฉ | ๊ธ | ํ |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- BFS
- tensorflow
- c++
- ํฌ๋ฃจ์ค์นผ
- object detection
- dfs
- ๋ฐฑํธ๋ํน
- ์ฐ์ ์์ ํ
- ์๋ฐ์คํฌ๋ฆฝํธ
- ํ๋ก์ด๋ ์์ฌ
- DP
- Overfitting
- ํ๊ณ ๋ก
- dropout
- ์กฐํฉ๋ก
- ๋ฏธ๋๋_ํ์ฌ์_๊ณผ๊ฑฐ๋ก
- 2023
- lazy propagation
- ์ด๋ถ ํ์
- ๋๋น ์ฐ์ ํ์
- ๋ฌธ์์ด
- ๊ฐ๋์_๋ง๋ก
- ์๊ณ ๋ฆฌ์ฆ
- NEXT
- pytorch
- ์ธ๊ทธ๋จผํธ ํธ๋ฆฌ
- ๋ค์ต์คํธ๋ผ
- ๋ถํ ์ ๋ณต
- back propagation
- ๊ฐ๋์ ๋ง๋ก
- Today
- Total
Doby's Lab
scheduler.get_last_lr(), ์ด์ ๋ Learning Rate๋ฅผ ์ด๋ ๊ฒ ํ์ธํ๋๋๋๋ค ๋ณธ๋ฌธ
scheduler.get_last_lr(), ์ด์ ๋ Learning Rate๋ฅผ ์ด๋ ๊ฒ ํ์ธํ๋๋๋๋ค
๋๋น(Doby) 2024. 7. 28. 13:52๐ค Problem
๋ชจ๋ธ์ ํ์ตํ๋ค๊ฐ ์ด์ํ๊ฒ ์ค์ผ์ค๋ฌ์ ๋ํ ์ถ๋ ฅ(Learning Rate์ ๋ํ ๋ณ๊ฒฝ ์ถ๋ ฅ)์ด ์์ด์ ์ด์ ๋ํด verbose
๋ฅผ True
๋ก ๋ฐ๊ฟ์ฃผ๋ ค๊ณ ์์
ํ ๋ด์ฉ์ ํ์ธํ๊ธฐ ์ํด ๊ณต์ ๋ฌธ์๋ฅผ ๋ค์ด๊ฐ ๋ดค๋ค๊ฐ ์๋ ๋ด์ฉ์ ํ์ธํ์ต๋๋ค.
๐ Solution
์ด์ ๋ ์ค์ผ์ค๋ฌ์ ๋ํด์ verbose
argument๋ฅผ ์ง์ํ์ง ์๊ฒ ๋ค๋ ๋ด์ฉ์ด์์ต๋๋ค. ํ์ง๋ง, ์ค์ผ์ค๋ฌ์ ๋ํ ๋ฉ์๋ get_last_lr()
์ ์ฌ์ฉํด ๋ณด๋ผ๊ณ ํฉ๋๋ค. ์ด ๋ฉ์๋๋ ์ค์ผ์ค๋ฌ๊ฐ ๋ง์ง๋ง์ผ๋ก ๊ณ์ฐํ Learning Rate๋ฅผ ์ถ๋ ฅํ๋ฉฐ, ์ด๋ 'ํ์ฌ ์ํฌํฌ์์ ์ด๋ ํ Learning Rate๋ก ํ์ต์ ์งํํ๊ฒ ๋๋๊ฐ'๋ฅผ ์๋ฏธํฉ๋๋ค.
๊ทธ๋์, ์๋ ๋ด์ฉ์ผ๋ก ์ ํ์ธ์ด ๋๋์ง๋ฅผ ์คํํ๊ธฐ ์ํด ๊ฐ๋จํ ์ฝ๋๋ฅผ ๋ง๋ค์ด์คฌ์ต๋๋ค.
๋งค ์ํฌํฌ๋ง๋ค ํ์ฌ์ Learning Rate๋ฅผ ์ถ๋ ฅํ๋๋ก ํด์ฃผ์์ผ๋ฉฐ, ๊ทธ์ ๋ํ ๊ฒฐ๊ณผ๋ ์๋์ ๊ฐ์ต๋๋ค.
(์๋ ์ฝ๋๋ ์๋์ ์ผ๋ก mode
๋ฅผ max
๋ก ๋์ด, ์ค์ด๋๋ loss
๊ฐ์ ๋ํด ์ค์ผ์ค๋ฌ ๋น ๋ฅด๊ฒ ์๋ํ๋๋ก ์ค๊ณํ์์ต๋๋ค.)
... # ์ ๋ชจ๋ธ, ์์ค ํจ์ ๋ฑ ๋ถํ์ํ ๋ด์ฉ ์๋ต
optimizer = Adam(model.parameters(), lr=0.001)
scheduler = ReduceLROnPlateau(optimizer, mode='max', patience=3)
epochs = 20
for epoch in range(epochs):
print(f"Epoch: {epoch+1:04d} - Learning Rate: {scheduler.get_last_lr()[0]:.8f}", end=' ')
optimizer.zero_grad()
output_tensor = model(input_tensor)
loss = loss_fn(output_tensor, target_tensor)
loss.backward()
optimizer.step()
print(f"Loss: {loss.item():.8f}")
scheduler.step(loss)
Epoch: 0001 - Learning Rate: 0.00100000 Loss: 0.25520608
Epoch: 0002 - Learning Rate: 0.00100000 Loss: 0.25505885
Epoch: 0003 - Learning Rate: 0.00100000 Loss: 0.25491315
Epoch: 0004 - Learning Rate: 0.00100000 Loss: 0.25476906
Epoch: 0005 - Learning Rate: 0.00100000 Loss: 0.25462645
Epoch: 0006 - Learning Rate: 0.00010000 Loss: 0.25448543
Epoch: 0007 - Learning Rate: 0.00010000 Loss: 0.25447142
Epoch: 0008 - Learning Rate: 0.00010000 Loss: 0.25445747
Epoch: 0009 - Learning Rate: 0.00010000 Loss: 0.25444353
Epoch: 0010 - Learning Rate: 0.00001000 Loss: 0.25442955
Epoch: 0011 - Learning Rate: 0.00001000 Loss: 0.25442815
Epoch: 0012 - Learning Rate: 0.00001000 Loss: 0.25442678
Epoch: 0013 - Learning Rate: 0.00001000 Loss: 0.25442535
Epoch: 0014 - Learning Rate: 0.00000100 Loss: 0.25442401
Epoch: 0015 - Learning Rate: 0.00000100 Loss: 0.25442386
Epoch: 0016 - Learning Rate: 0.00000100 Loss: 0.25442374
Epoch: 0017 - Learning Rate: 0.00000100 Loss: 0.25442359
Epoch: 0018 - Learning Rate: 0.00000010 Loss: 0.25442347
Epoch: 0019 - Learning Rate: 0.00000010 Loss: 0.25442344
Epoch: 0020 - Learning Rate: 0.00000010 Loss: 0.25442341
์ ๊ฒฐ๊ณผ๋ฅผ ํตํด scheduler.get_last_lr()[0]
์ฝ๋๊ฐ ํ์ฌ์ Learning Rate๋ฅผ ๊ฐ์ ธ์ค๋ ๊ฒ์ ํ์ธํ ์ ์์์ต๋๋ค. ์ธ๋ฑ์ฑ์ ํด์ค ์ด์ ๋ ํด๋น ๋ฉ์๋์ ๋ฆฌํด ํ์
์ด List[float]
๋ผ์ ์์ ๊ฐ์ด ๊ฐ์ ๋ฐ์์ค๋๋ก ํด์ฃผ์์ต๋๋ค.
๐ Reference
ReduceLROnPlateau — PyTorch 2.4 documentation
Shortcuts
pytorch.org