Skip to content

Commit

Permalink
post
Browse files Browse the repository at this point in the history
  • Loading branch information
chojinie committed Sep 29, 2024
1 parent 6456523 commit c47ea2b
Show file tree
Hide file tree
Showing 13 changed files with 2,010 additions and 0 deletions.
Binary file modified .DS_Store
Binary file not shown.
321 changes: 321 additions & 0 deletions _posts/2023-05-22-computer-vision-optical-flow - 복사본.md

Large diffs are not rendered by default.

271 changes: 271 additions & 0 deletions _posts/2023-05-23-human-pose-estimation - 복사본.md

Large diffs are not rendered by default.

148 changes: 148 additions & 0 deletions _posts/2023-05-26-numpy-study.md.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
---
layout: post
title: Numpy study
date: 2023-05-26
description: recording_a Summary of Numpy
tags: numpy math study
categories: study math
related_posts: false
toc:
sidebar: left
---

### numpy.random.choice(a, size=None, replace=True, p=None)

a = 1차원 배열 또는 정수 (정수인 경우, np.arrange(a)와 같은 배열 생성)<br>
size = 정수 또는 튜플(튜플인 경우, 행렬로 리턴됨. (x, y, z) >> x*y*z)<br>
replace = 중복 허용 여부, boolean<br>
p = 1차원 배열, 각 데이터가 선택될 확률<br>

example
```
np.random.choice(5, 3)
array([0, 3, 4])
# 0 이상 5미만인 정수 중 3개를 출력(replace=True가 default로 숨어져 있으므로 중복 허용)
```
```
np.random.choice(5, 3, replace=False)
array([3, 1, 0])
# 0 이상 5미만인 정수 중 3개를 출력(replace=False이므로 중복 불가)
```

### flatnonzero
```
import numpy as np
a = np.array([1.2, -1.3, 2.1, 5.0, 4.7])
print(np.flatnonzero(a>2)) *# [2 3 4]*
# 2보다 큰 원소의 index를 array로 리턴.
```

### np.reshape(X_train, (X_train.shape[0], -1))

np.reshape: array를 원하는 형태로 reshape할 수 있게 해주는 라이브러리.

X_train: reshape하고 싶은 array<br>
(X_train.shape[0], -1): X_train이 목표로 하는 모양을 의미합니다.<br>
X_train.shape[0]: X_train array의 row의 수를 의미합니다. <br>
X_train.shape[0]을 이용하여 reshape된 array에서 row의 숫자가 바뀌지 않고 유지되게 됩니다.<br>
-1: 이것은 NumPy가 제공된 행 수와 원래 배열의 전체 크기를 기반으로 재구성된 배열의 열 수를 자동으로 결정하도록 지시하는 자리 표시자 값입니다.<br>
-1은 차원이 자동으로 추론되고 조정되어야 함을 나타냅니다. 요약하면, 이 코드 라인은 X_train 배열의 형태를 재구성하며, 행 수는 유지되고 원본 배열의 크기에 따라 열 수가 자동으로 결정됩니다.<br>

### np.zeros

numpy.zeros(shape, dtype=float, order='C', *, like=None)<br>
Return a new array of given shape and type, filled with zeros.<br>

Parameters<br>
- shape : int or tuple of ints
- np.zeros((2, 1))
- array([[ 0.],
[ 0.]])

- dtype : data-type, optional
The desired data-type for the array, e.g., numpy.int8. Default is numpy.float64.<br>

- order : {‘C’, ‘F’}, optional, default: ‘C’<br>
Whether to store multi-dimensional data in row-major (C-style) or column-major (Fortran-style) order in memory.<br>

- like : array_like, optional<br>
Reference object to allow the creation of arrays which are not NumPy arrays. If an array-like passed in as like supports the __array_function__ protocol, the result will be defined by it. In this case, it ensures the creation of an array object compatible with that passed in via this argument.

### array 인덱싱 이해하기

#### 기본 인덱싱

Numpy array의 꽃은 인덱싱입니다. arr 라는 array가 있을 때, arr[5]와 같이 특정한 인덱스를 명시할 수도 있고, arr[5:8]과 같이 범위 형태의 인덱스를 명시할 수도 있습니다.<br>
arr[:]의 경우 해당 array의 전체 성분을 모두 가져옵니다.<br>

이러한 방식은 2차원 array에 대해서도 유사한 방식으로 적용됩니다. arr2라는 2차원 array를 정의한 뒤,
arr2[2, :]를 실행하면, arr2에서 인덱스가 '2'에 해당하는 행(3행)의 모든 성분이 1차원 array의 형태로 얻어집니다.<br>
arr2[:, 3]을 실행하면 arr2에서 인덱스가 '3'에 해당하는 열(4열)의 모든 성분이 1차원 array의 형태로 얻어집니다.<br>

2차원 array는 이렇게 두개의 인덱스를 받을 수 있는데, ","를 기준으로 앞부분에는 행의 인덱스가 뒷부분에는 열의 인덱스가 입력됩니다.
arr2[1:3, :] 혹은 arr2[:, :2]와 같이, 행 또는 열에 범위 인덱스를 적용하여 여러 개의 행 혹은 열을 얻을 수도 있습니다.<br>

한편 2차원 array에서 4행 3열에 위치한 하나의 성분을 얻고자 할 때는 arr2[3,2]를 실행하면 됩니다.
인덱싱을 통해 선택한 성분에 새로운 값을 대입하는 경우에도, arr2[:2, 1:3] = 0 과 같이 입력값을 넣으면 됩니다.<br>

### NumPy 어레이 정렬 (np.argsort)
#### 기본 사용(오름차순 정렬)

<!--코드블럭-->
** Input **
```
import numpy as np
a = np.array([1.5, 0.2, 4.2, 2.5])
s = a.argsort()
print(s)
print(a[s])
```
** Output **

```
[1 0 3 2]
[0.2 1.5 2.5 4.2]
```

a는 정렬되지 않은 숫자들의 어레이입니다.
a.argsort()는 어레이 a를 정렬하는 인덱스의 어레이 [1 0 3 2]를 반환합니다.
a[s]와 같이 인덱스의 어레이 s를 사용해서 어레이 a를 다시 정렬하면,
오름차순으로 정렬된 어레이 [0.2 1.5 2.5 4.2]가 됩니다.

#### 내림차순 정렬

** Input **

```
import numpy as np
a = np.array([1.5, 0.2, 4.2, 2.5])
s = a.argsort()
print(s)
print(a[s[::-1]])
print(a[s][::-1])
```
** Output **

```
[1 0 3 2]
[4.2 2.5 1.5 0.2]
[4.2 2.5 1.5 0.2]
```
<p>
내림차순으로 정렬된 어레이를 얻기 위해서는
a[s[::-1]]와 같이 인덱스 어레이를 뒤집어서 정렬에 사용하거나,
a[s][::-1]과 같이 오름차순으로 정렬된 어레이를 뒤집어주면 됩니다.
</p>


### Reference

https://numpy.org/doc/stable/reference/random/generated/numpy.random.choice.html
<br>
32 changes: 32 additions & 0 deletions _posts/2023-05-27-solution-cs231n-assignment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
layout: post
title: cs231n assignment solution
date: 2023-05-27
description: recording_a Summary of assignment
tags: cs231 study AI
categories: study cs231 AI
related_posts: false
toc:
sidebar: left
---

## Assignment 1
### Inline Question 1
Notice the structured patterns in the distance matrix, where some rows or columns are visibly brighter.
(Note that with the default color scheme black indicates low distances while white indicates high distances.)

<div class="row mt-3">
<div class="col-sm mt-3 mt-md-0">
{% include figure.html path="assets/img/assignmentinlinequestion1.png" class="img-fluid rounded z-depth-1" zoomable=true %}
</div>
</div>

- What in the data is the cause behind the distinctly bright rows?
- What causes the columns?

$$ \color{blue}Your Answer : $$ *fill this in.*

<p>
- 훈련 데이터 세트에 포함되지 않은 클래스로부터의 관측이거나, 적어도 대부분의 훈련 데이터와 매우 다른 관측일 가능성이 높습니다. 아마도 배경 색상과 관련하여 큰 차이가 있을 것입니다.<br>
- 학습 데이터 포인트가 테스트 데이터 내의 어떠한 포인트와도 비슷하지 않음을 의미합니다.
</p>
131 changes: 131 additions & 0 deletions _posts/2023-05-28-cs231-Introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
---
layout: post
title: cs231n Summary - Introduction
date: 2023-05-28
description: recording_a Summary of lecture
tags: cs231 study AI
categories: study cs231 AI
related_posts: True
giscus_comments: true
toc:
sidebar: left
---

본 시리즈는 cs231n을 공부하고 그 내용을 정리하기 위해 작성됩니다. 시리즈에 관련된 모든 출처는 기본적으로 http://cs231n.stanford.edu/schedule.html 의 강의 내용을 기반으로 하고 있습니다.

### 강의 목표

아래 이미지에서 교집합 부분에 해당하는 부분을 학습합니다.

<div class="row mt-3">
<div class="col-sm mt-3 mt-md-0">
{% include figure.html path="/assets/img/cs231n/assignment1/pic1.png" class="img-fluid rounded z-depth-1" zoomable=true %}
</div>

</div>


### Agenda
#### 컴퓨터 비전과 딥러닝의 기원의 요약

<div class="row mt-3">
<div class="col-sm mt-3 mt-md-0">
{% include figure.html path="/assets/img/cs231n/assignment1/pic2.png" class="img-fluid rounded z-depth-1" zoomable=true %}
</div>
<div class="col-sm mt-3 mt-md-0">
{% include figure.html path="/assets/img/cs231n/assignment1/pic3.png" class="img-fluid rounded z-depth-1" zoomable=true %}
</div>
</div>

카메라와 컴퓨터가 개발되면서, 어떻게 하면 컴퓨터가 사람과 같이 vision을 가질 수 있을지 연구하게 되었습니다.
이를 Computer Vision 분야라고 합니다.

<div class="row mt-3">
<div class="col-sm mt-3 mt-md-0">
{% include figure.html path="/assets/img/cs231n/assignment1/pic4.png" class="img-fluid rounded z-depth-1" zoomable=true %}
</div>
<div class="col-sm mt-3 mt-md-0">
{% include figure.html path="/assets/img/cs231n/assignment1/pic5.png" class="img-fluid rounded z-depth-1" zoomable=true %}
</div>
</div>
Hubel and Wiesel, 1959의 연구를 보면 생명체가 사물을 인식할 때 패턴에 따라 특정한 신호가 나오는 것을
알게 되었고 이를 컴퓨터에 적용하면 어떻게 될까에서 시작한 것 같습니다. 고전적인 Computer Vision
분야에서는 특징점을 찾아내서 사물을 구분하기도 했습니다.

<div class="row mt-3">
<div class="col-sm mt-3 mt-md-0">
{% include figure.html path="/assets/img/cs231n/assignment1/pic8.png" class="img-fluid rounded z-depth-1" zoomable=true %}
</div>
<div class="col-sm mt-3 mt-md-0">
{% include figure.html path="/assets/img/cs231n/assignment1/pic7.png" class="img-fluid rounded z-depth-1" zoomable=true %}
</div>
</div>
사람과 물체를 인식할 때 부분부분별로 따로 떼어서 인식하기도 했습니다. 또한, 인간이 사물을 파악할 때 edge(가장자리)로 구분 짓는다는 특징을 이용하여 edge detection 분야가 연구되기도 했습니다.

<div class="row mt-3">
<div class="col-sm mt-3 mt-md-0">
{% include figure.html path="/assets/img/cs231n/assignment1/pic8.png" class="img-fluid rounded z-depth-1" zoomable=true %}
</div>
<div class="col-sm mt-3 mt-md-0">
{% include figure.html path="/assets/img/cs231n/assignment1/pic7.png" class="img-fluid rounded z-depth-1" zoomable=true %}
</div>
</div>


#### cs231n Overview

##### Deep Learning Basics - Image Classification
<div class="row mt-3">
<div class="col-sm mt-3 mt-md-0">
{% include figure.html path="/assets/img/cs231n/assignment1/pic35.png" class="img-fluid rounded z-depth-1" zoomable=true %}
</div>
</div>
이미지 상의 대상을 무엇으로 분류할지를 classification task라고 합니다. 다양한 방법으로 이를 구현할 수 있습니다.

<div class="row mt-3">
<div class="col-sm mt-3 mt-md-0">
{% include figure.html path="/assets/img/cs231n/assignment1/pic36.png" class="img-fluid rounded z-depth-1" zoomable=true %}
</div>

<div class="col-sm mt-3 mt-md-0">
{% include figure.html path="/assets/img/cs231n/assignment1/pic37.png" class="img-fluid rounded z-depth-1" zoomable=true %}
</div>
<div class="col-sm mt-3 mt-md-0">
{% include figure.html path="/assets/img/cs231n/assignment1/pic38.png" class="img-fluid rounded z-depth-1" zoomable=true %}
</div>
</div>

선분의 좌측이면 고양이 우측이면 강아지와 같은 방식으로 Classifier을 구현할 수 있습니다. 모델의 정확성을 높이기 위하여 Regularization과 Optimization을 수행하기도 합니다. Neural Network방식의 Classifier도 존재합니다.

##### Perceiving and Understanding the Visual World

<div class="row mt-3">
<div class="col-sm mt-3 mt-md-0">
{% include figure.html path="/assets/img/cs231n/assignment1/pic39.png" class="img-fluid rounded z-depth-1" zoomable=true %}
</div>
</div>
컴퓨터가 사물을 분류하는 등 역할을 수행하기 위해서는 결국 사물을 "인지"하고 "이해"하는 과정을 거쳐야 합니다.
사람에게는 정말 쉬운 작업이지만 컴퓨터에게는 이를 위해 다양한 task를 수행해야하며 여기에 맞는 모델이 필요합니다.


<div class="row mt-3">
<div class="col-sm mt-3 mt-md-0">
{% include figure.html path="/assets/img/cs231n/assignment1/pic40.png" class="img-fluid rounded z-depth-1" zoomable=true %}
</div>
<div class="col-sm mt-3 mt-md-0">
{% include figure.html path="/assets/img/cs231n/assignment1/pic41.png" class="img-fluid rounded z-depth-1" zoomable=true %}
</div>
</div>


<div class="row mt-3">
<div class="col-sm mt-3 mt-md-0">
{% include figure.html path="/assets/img/cs231n/assignment1/pic42.png" class="img-fluid rounded z-depth-1" zoomable=true %}
</div>
<div class="col-sm mt-3 mt-md-0">
{% include figure.html path="/assets/img/cs231n/assignment1/pic43.png" class="img-fluid rounded z-depth-1" zoomable=true %}
</div>
</div>

## 참고
http://cs231n.stanford.edu/schedule.html
Loading

0 comments on commit c47ea2b

Please sign in to comment.