| μΌ | μ | ν | μ | λͺ© | κΈ | ν |
|---|---|---|---|---|---|---|
| 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 | 29 | 30 | 31 |
- λ°±μ€
- TDD
- ν΄λ¦°μ½λ
- latent factor model
- μκ³ λ¦¬μ¦
- 무결μ±μ μ§
- DROPTABLE
- μΈλλ³κ°λΉμ§μ»¬λ ν°
- ALTERTABLE
- SQLDDL
- CREATETABLE
- 컨ν μ΄λκ°μ²΄
- μ μ¬μμλͺ¨λΈ
- Python
- Key μ’ λ₯
- 무결μ±μ μ§λ©μ»€λμ¦
- ν€ μ’ λ₯
- RENAMETABLE
- μ¬μ΄ν·λ°
- SQL
- sklearn
- latent factor
- Hyperlink Graphs
- 무결μ±
- μ£Όμ±λΆ μ°ΎκΈ°
- λ¬Έμμ΄
- νμ΄μ¬
- knn_classify
- ν
- λΆκ½λ°μ΄ν°μ
- Today
- Total
DonHurry
step38. νμ λ³ν ν¨μ λ³Έλ¬Έ
π’ λ³Έ ν¬μ€ν μ λ°λ°λ₯λΆν° μμνλ λ₯λ¬λ3μ κΈ°λ°μΌλ‘ μμ±νμμ΅λλ€. λ°°μ΄ λ΄μ©μ κΈ°λ‘νκ³ , κ°μΈμ μΈ κ³΅λΆλ₯Ό μν΄ μμ±νλ ν¬μ€ν μ λλ€. μμΈν λ΄μ©μ κ΅μ¬ ꡬ맀λ₯Ό κ°λ ₯ μΆμ²λ립λλ€.

μ΄λ² λ¨κ³μμλ ν μμ νμμ λ³ννλ reshape ν¨μμ νλ ¬μ μ μΉνλ transpose ν¨μλ₯Ό μ΄ν΄λ³΄κ² μ΅λλ€. λνμ΄ λΌμ΄λΈλ¬λ¦¬μλ μ΄λ―Έ reshape ν¨μκ° μ‘΄μ¬ν©λλ€. νμ§λ§ DeZero λ²μ μμ reshape ν¨μλ μμ νλ₯Ό κ³ λ €ν΄μΌν©λλ€. μ΄λ κ°μ₯ μ€μν κ²μ λ³μμ λ°μ΄ν°μ κΈ°μΈκΈ°μ νμμ΄ μΌμΉν΄μΌνλ€λ κ²μ λλ€. x.data.shapeμ x.grad.shapeκ° κ°μμΌ νλ€λ κ²μ΄μ£ .
ꡬνν λ μ£Όμν΄μΌν μ μ μμ ν μμλ μ§μ ꡬνν ν¨μλ₯Ό νμ©ν΄μΌ νλ€λ κ²μ λλ€. backward(gy)μμ μΈμ gyκ° Variable μΈμ€ν΄μ€μ΄κΈ° λλ¬Έμ λλ€. λ°λΌμ Variable μΈμ€ν΄μ€λ₯Ό λ€λ£° μ μλ DeZeroμ ν¨μλ‘ κ³μ°ν΄μΌ ν©λλ€.
class Reshape(Function):
def __init__(self, shape):
self.shape = shape
def forward(self, x):
self.x_shape = x.shape
y = x.reshape(self.shape)
return y
def backward(self, gy):
return reshape(gy, self.x_shape)
def reshape(x, shape):
if x.shape == shape:
return as_variable(x)
return Reshape(shape)(x)
λ€μμΌλ‘ Variable ν΄λμ€μ μ½λλ₯Ό μΆκ°ν΄μ£Όμ΄μΌ ν©λλ€. νν, 리μ€νΈ λ± λ€μνκ² λ³μλ₯Ό λ°κΈ° μν¨μ λλ€. μλ₯Ό λ€μ΄ y = x.reshape(2, 3) νμμ κ°λ³ μΈμλ λ°μ μ μκ² λ©λλ€.
class Variable:
...
def reshape(self, *shape):
if len(shape) == 1 and isinstance(shape[0], (tuple, list)):
shape = shape[0]
return dezero.functions.reshape(self, shape)
λ€μμΌλ‘ νλ ¬μ μ μΉλ₯Ό μν transposeμ λλ€. μλ₯Ό λ€μ΄ xμ νμμ΄ (2, 3)μ΄λΌλ©΄ (3, 2)λ‘ λ³νν΄μ€ μ μμ΅λλ€. μμ νμ κ²½μ° μμ νμ λ°λμ λ³νμ΄ μ΄λ£¨μ΄μ§κΈ° λλ¬Έμ μΆλ ₯μμ μ ν΄μ§ κΈ°μΈκΈ°λ₯Ό transpose ν¨μλ₯Ό νμ©ν΄ λ³νν©λλ€. λ³Έλ μ± μμλ κ°λ¨νκ² 2μ°¨μ ν μμΌ λλ‘ νμ νμ¬ μ½λλ₯Ό ꡬμ±νκ³ μμ΅λλ€. νμ§λ§ μ€μ transpose ν¨μλ λ λ²μ©μ μΌλ‘ μ¬μ©λ©λλ€. [κ·Έλ¦Ό 38-4]μ κ°μ κΈ°λ₯μ΄ λνμ μΈ μμ λλ€.

μ΄λ¬ν κΈ°λ₯μ ν¬ν¨ν κ²μ΄ μλ μ½λμ λλ€. μμ νμμλ λνμ΄λ₯Ό νμ©νμ¬ transposeλ₯Ό μ§ννμ§λ§ μμ νμ κ²½μ°μλ reshapeμ λ§μ°¬κ°μ§λ‘ μ§μ ꡬνν ν¨μλ₯Ό νμ©ν©λλ€.
class Transpose(Function):
def __init__(self, axes=None):
self.axes = axes
def forward(self, x):
y = x.transpose(self.axes)
return y
def backward(self, gy):
if self.axes is None:
return transpose(gy)
axes_len = len(self.axes)
inv_axes = tuple(np.argsort([ax % axes_len for ax in self.axes]))
return transpose(gy, inv_axes)
def transpose(x, axes=None):
return Transpose(axes)(x)
@property λ°μ½λ μ΄ν°λ y = x.transpose()λ₯Ό y = x.Tμ κ°μ΄ μ¬μ©ν μ μλλ‘ ν΄μ€λλ€.
class Variable:
...
def transpose(self, *axes):
if len(axes) == 0:
axes = None
elif len(axes) == 1:
if isinstance(axes[0], (tuple, list)) or axes[0] is None:
axes = axes[0]
return dezero.functions.transpose(self, axes)
@property
def T(self):
return dezero.functions.transpose(self)'DeZero > π»μ 4κ³ μ§' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
| step42. μ ν νκ· (0) | 2023.02.18 |
|---|---|
| step41. νλ ¬μ κ³± (0) | 2023.02.16 |
| step40. λΈλ‘λμΊμ€νΈ ν¨μ (0) | 2023.02.15 |
| step39. ν©κ³ ν¨μ (0) | 2023.02.14 |
| step37. ν μλ₯Ό λ€λ£¨λ€ (0) | 2023.02.12 |