본문 바로가기
728x90
반응형

pytorch21

[DL] PyTorch-Hook PyTorch의 hook은Neural Network 내부의 계산 과정을 관찰하거나,특정 시점에서 개입할 수 있도록 해주는 기능 (사실은 function 또는 instance method임).을 제공함. 이를 통해 forward 중간 출력 및 backward 에서의 gradient, 또는 입력 값 자체를 가로채어 확인하거나 수정할 수 있음.Hook이 제대로 동작하기 위해선 forward를 직접 호출해선 안됨. 관련 내용은 다음 URL에서 __call__ 과 forward 관련부분 읽어볼것:2024.04.12 - [Python] - [PyTorch] Custom Model 과 torch.nn.Module의 메서드들. [PyTorch] Custom Model 과 torch.nn.Module의 메서드들.Cust.. 2025. 4. 10.
[DL] torch.nn.Linear 에 대하여 torch.nn.Linear는 PyTorch에서 선형 변환(linear transformation)을 수행하는 핵심 Module임. 다음의 이름으로도 불림.Fully Connected Layer (FC Layer)Dense LayerConstructor (생성자)torch.nn.Linear( in_features, out_features, bias=True,) TensorFlow의 Dense와 유사하나, activation등을 내장하고 있지 않음.파라미터설명in_featuresinput tensor의 마지막 차원 크기 (int)out_featuresoutput tensor의 마지막 차원 크기 (int)biasbias 사용 여부 (기본값: True)수학적 정의linear module은 .. 2025. 4. 10.
[DL] Tensor 다루기 기초 - PyTorch 중심 https://dsaint31.tistory.com/891 [ML] Tensor: Scalar, Vector, Matrix.Tensor 종류1. Scalar (0차원 tensor)하나의 숫자로 표현되는 가장 기본적인 형태.크기(magnitude)만을 가지며 방향은 없음.예시: 온도(25°C), 나이(20), 가격(1000원)# 파이썬/NumPy에서의 표현scalar = 5.02. Vector (dsaint31.tistory.comhttps://dsaint31.tistory.com/456 [Programming] Primitive Data Type : C, C++, NumPy, TorchPrimitive Data Type이(Unboxed type)란?C, C++, NumPy, PyTorch, TensorF.. 2025. 3. 7.
[DL] Classification 을 위한 Activation Func. 와 Loss Func: PyTorch PyTorch: Classification에서의 Output Func(~Activation Func.)와 Loss Func. 요약PyTorch는 다양한 종류의 loss function(손실 함수)와 activation function(활성화 함수)를 제공하는데,이 중에서 classification task를 수행하는 모델에서 사용되는 것들을 위주로 정리함.최종 출력 함수로 사용되는 activation functions 와 이들과 같이 사용되는 loss functions는 다음과 같음.최종 출력으로로사용되는 activation functions: Sigmoid, Softmax, LogSoftmaxloss functions: BCELoss, BCEWithLogitsLoss, CrossEntropyLoss, .. 2024. 5. 23.
[PyTorch] Custom Model 과 torch.nn.Module의 메서드들. Custom Model 만들기0. nn.Module torch.nn.Module은 PyTorch에서 모든 신경망 모델과 계층의 기반이 되는 클래스임.Custom Model (사용자 정의 모델)부터 Built-in Layer(nn.Linear, nn.Conv2d, etc.)까지 전부 nn.Module을 상속받아 만들어짐.Model (or Submodule)을 구조화하고 학습 가능한 parameters를 관리하는 데 핵심적인 역할을 함. PyTorch에선 Model과 Layer 모두 nn.Module 의 sub-class가 됨. 때문에 모든 Custom Model은 nn.Module (또는 그 sub-class)을 상속하여 만들어진다. nn.Module은 다음의 특징을 가짐.생성자(__init__)에서 모델.. 2024. 4. 12.
[PyTorch] CustomANN Example: From Celsius to Fahrenheit Optional Librariestorchviz: 0.0.2torchsummary: 1.5.1pip install --quiet torchvizpip install torchsummaryRequired Librariestorch : 2.2.1+cu121np : 1.25.2import numpy as npimport torchimport matplotlib.pyplot as plt# import torchviz, torchsummaryfrom torch.nn import Module, init, Linear, Parameter, ReLUfrom torch import optimSimple Data Generationdef gen_xy(cnt, std=4.): x = np.linspace(-10,10,.. 2024. 4. 12.
728x90
반응형