전체 글

전체 글

    List comprehension보다 for문이 빠른 경우

    List comprehension보다 for문이 빠른 경우

    보통은 list comprehension이 반복문보다 처리 속도가 빠르다고 알고 있다. 그런데 그렇지 않은 경우도 존재한다. 다음과 같은 경우를 예로 살펴 보자. 어떤 pattern과 text를 입력 받아, 해당 pattern이 text에 포함되어 있는지 검사하는 코드이다. 결과로 pattern이 시작되는 text의 index를 반환한다. def read_input(): return (input().rstrip(), input().rstrip()) def print_occurrences(output): print(' '.join(map(str, output))) def get_occurrences(pattern, text): return [ i for i in range(len(text) - len(pa..

    DeeplabV3+ 모델 전이 학습(transfer learning) 쉽게 구현하기

    DeeplabV3+ 모델 전이 학습(transfer learning) 쉽게 구현하기

    아래 repository를 기반으로 작성하였다. GitHub - qubvel/segmentation_models.pytorch: Segmentation models with pretrained backbones. PyTorch. Segmentation models with pretrained backbones. PyTorch. - GitHub - qubvel/segmentation_models.pytorch: Segmentation models with pretrained backbones. PyTorch. github.com 1. Pretrained 모델 로드 # train.py pretrained_model = smp.DeepLabV3Plus( encoder_name='resnet50', encode..

    AMP(Automatic Mixed Precision) 쉽게 적용하기

    AMP(Automatic Mixed Precision) 쉽게 적용하기

    pytorch 1.6 이상에서는 torch.cuda.amp 패키지를 이용해 편리하게 AMP를 적용할 수 있다. * AMP는 float32와 float16을 함께 적절히 사용함으로써 빠른 연산 속도와 효율적인 메모리 활용이 가능하도록 해준다. 내 딥러닝 모델에 AMP를 적용하려면 앞서 말한 패키지에서 두 가지를 import 해야 한다. from torch.cuda.amp import autocast, GradScaler 우선 GradScaler는 mixed-precision으로 학습을 진행할 때 gradient scaling을 수행하는 역할을 한다. 즉 backpropagation 중 gradient가 너무 작아지는 것을 방지하여 floating-point 형식으로 정확하게 표현될 수 없는 숫자가 되는 문..

    AWS ECR 이미지와 lambda로 딥러닝 Serverless 서비스 만들기 - UnicodeDecodeError 해결

    AWS ECR 이미지와 lambda로 딥러닝 Serverless 서비스 만들기 - UnicodeDecodeError 해결

    Error message: Traceback (most recent call last): File "/var/runtime/bootstrap.py", line 60, in main() File "/var/runtime/bootstrap.py", line 55, in main add_default_site_directories() ... 중략 ... File "/var/lang/lib/python3.9/codecs.py", line 322, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 64: ..

    K-means Clustering

    K-means Clustering

    K-means cluster analysis is an unsupervised machine learning algorithm used to partition a dataset into distinct groups or clusters based on similarity of data points. It aims to find K cluster centers in such a way that the within-cluster sum of squares is minimized. Here's how k-means cluster analysis works: Initial Setup: The algorithm begins by randomly selecting K initial cluster centers fr..

    Lasso regression

    Lasso regression

    Lasso regression, also known as L1 regularization, is a linear regression technique that incorporates regularization to prevent overfitting and improve the model's interpretability. It adds a penalty term to the standard least squares objective function, which encourages the model to select only a subset of the available features by shrinking the coefficients of irrelevant or less important feat..

    Random Forest

    The concept of a random forest is a popular machine learning technique used for both classification and regression tasks. It is an ensemble method that combines multiple decision trees to make predictions. Here's how a random forest works: Data Preparation: The first step is to prepare the training data, which includes input features and corresponding labels or target values. Each instance in th..

    Decision Tree

    Decision Tree

    A decision tree is a supervised machine learning algorithm that is used for both classification and regression tasks. It is a flowchart-like structure where each internal node represents a feature or attribute, each branch represents a decision rule, and each leaf node represents the outcome or class label. The concept of a decision tree is based on a series of binary decisions that lead to a fi..

    Visual SLAM 기법의 종류

    Visual SLAM 기법의 종류

    SLAM이란 Simultaneous Localization And Mapping, 즉 로봇이나 자율주행 자동차가 자신을 둘러싼 환경에 대한 맵(Map)을 생성하고, 그 안에서 자신의 위치를 추정하는 기술이다. LiDAR(Light Detection And Ranging) 센서를 이용한 SLAM은 비교적 간단하고, 더 자세한 기법이랄 것이 없기 때문에 Visual SLAM의 다양한 방법들을 간략하게 정리해 보았다. 1. Filter based SLAM 로봇의 position과 방향, 환경 정보 같은 것을 포함하는 시스템 상태(state)를 추정하기 위해 수학적 필터들을 이용하는 알고리즘이다. 필터들은 시간에 따른 더 정확한 상태 추정을 위해 센서 데이터에 반복적으로 적용된다. 예를 들어 Kalman 필터는..

    초기 신경망 이론과 모델

    초기 신경망 이론과 모델

    현재의 딥러닝 구조와 방식을 더 깊게 이해하기 위해 초기 신경망 이론과 모델에 대해 정리해 보았다. 1943년 맥컬럭-피츠(McCulloch-Pitts) 뉴런 맥컬럭과 피츠는 최초로 인간 두뇌의 뉴런을 모델링했다. 그 바탕에는 '인간의 두뇌는 논리적 서술을 구현하는 이진 원소들의 집합'이라는 추측이 있었다. 신경 활동의 '전부 아니면 전무(All-or-nothing)'적인 특성 때문에 신경계의 일과 그들 사이의 관계들은 명제 논리(Propositional logic)로 취급된다. 모든 망의 행동은 이러한 관점에서 기술될 수 있다. (중략) 어떠한 조건들을 만족시키려는 논리적 표현에 대하여, 우리는 그것이 기술하는 방법대로 행동하는 망을 찾을 수 있다. 즉 어떠한 논리적 명제에 대하여 참(True) 혹은 ..