모두를 위한 딥러닝 - Lec 00, ML Lec 01

Dylan·2022년 7월 25일
0
post-thumbnail

Lec 00 - Machine/Deep learning 수업의 개요와 일정

Audience

  • Want to understand basic machine learning (ML)
  • No/weak math/computer science background
    • y = Wx + b (y=ax+b)
  • Want to use ML as black-box with basic understanding
  • Want to use Tensorflow and Python (optional)

Goals

  • Basic understanding of machine learning algorithms
    • Linear regression, Logistic regression(classification)
    • Neural networks, Convolutional Neural Network, Recurrent Neural Network
  • Solve your problems using machine learning tools
    • Tensorflow and Python

Course structure

  • About 10 min Lecture
  • Programming tutorial using Tensorflow

Acknowledgement

Schedule

  • Machine learning basic concepts
  • Linear regression
  • Logistic regression (classification)
  • Multivariable (Vector) linear/logistic regression
  • Neural networks
  • Deep learning
    • CNN
    • RNN
    • Bidirectional Neural networks

ML lec 01 - 기본적인 Machine Learning 의 용어와 개념 설명

Basic concepts

  • What is ML?
  • What is learning?
    • supervised
    • unsupervised
  • What is regression?
  • What is classification?

Machine Learning

  • Limitations of explicit programming
    • Spam filter: many rules
    • Automatic driving : too many rules
  • Machine learning : "Field of study that gives computers the ability to learn without being explicitly programmed" Arthur Samuel (1959)

    프로그램인데 이것을 개발자가 일일히 어떻게 하는지를 정하지 않고 이 프로그램 자체가 데이터를 보고 학습해서 뭔가를 배우는 영역을 갖는 프로그램을 머신러닝이라 한다.

Supervised/Unsupervised learning

  • Supervised learning:
    • learning with labeled examples - training set

출처 : https://cs231n.github.io/classification/

어떤 하나의 정해져있는 데이터로 학습을 한다 - 수퍼바이저드 러닝

  • Unsupervised learning: un-labeled data
    • Google news grouping
    • Word clustering

데이터를 보고 스스로 학습한다 - 언수퍼바이저드 러닝

Supervised learning

  • Most common problem type in ML
    • Image labeling: learning from tagged images
    • Email spam filter: learning from labeled (spam or ham) email
    • Predicting exam score: learning from previous exam score and time spent

Training data set

Types of supervised learning

  • Predicting final exam score based on time spent

    • regression
  • Pass/non-pass based on time spent

    • binary classification
  • Letter grade (A, B, C, E and F) based on time spent

    • multi-label classification

    수퍼바이저드 러닝을 다룰 때 대게 3가지로 나뉘어 질 수 있다

ML lab 01 - TensorFlow의 설치 및 기본적인 operations (new)

TensorFlow

  • TensorFlow is an open source software library for numerical computation using data flow graphs.
  • Python!

What is a Data Flow Graph?

  • Nodes in the graph represent mathematical operations
  • Edges represent the multidimensional data arrays(tensors) communicated between them.

Installing TensorFlow

2022년이 되면서 텐서플로우2 설치시 파이썬 지원 버전이 아래 그림처럼 바뀌었다 참고바람!

텐서 플로우 파이썬 내부에서 설치하기

1. pip 최신 업그레이드

python -m pip install --upgrade pip

2. 텐서플로우 설치

pip install tensorflow

텐서플로우 import시 발생한 오류

>>> import tensorflow.compat.v1 as tf
    2022-07-26 11:21:12.314794: \ tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'cudart64_110.dll'; dlerror: cudart64_110.dll not found
    2022-07-26 11:21:12.314975: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.

간략하게 얘기해서 CUDA 버전이 안맞아서 생긴 오류이다 맞는버전을 검색해서 다운로드 후 재 실행하면 됌

Check installation and version

해당 그림은 17년도에 올라온거라 현재 2022년도 기준 텐서플로우는 2.0버전 이상으로 올라가면서 더이상 Session 모듈을 지원하지 않게 되었다. 대신 아래와 같은 코드를 작성하면 Session 사용이 가능하다.

import tensorflow.compat.v1 as tf

tf.disable_v2_behavior()

TensorFlow Hello World!

	# Create a constant op
    # This op is added as a node to the default graph
    hello = tf.constant("Hello, TEnsorFlow!")
    
    # seart a TF session
    sess = tf.Session()
    
    # run the op and det result
    print(sess run(hello))
    
    b'Hello, TensorFlow!'

Computational Graph

(1) Build graph (tensors) using TensorFlow operations

	node1 = tf.constant(3.0, tf.float32)
    node2 = tf.constant(4.0) # also tf.float32 implicitly
    node3 = tf.add(node1, node2) # node3 = node1 + node2
	print("node1:", node1, "node2:", node2)
    print("node3: ", node3)
    
    node1: Tensor("Const_1:0", shape=(), dtype=float32) node2: Tensor("const_2:0", shape=(), dtype=float32)
    node3: Tensor("Add:0", shpe=(), dtype=float32)

바로 출력하면 결과값이 나오는게 아니라 형태가 나오게 된다.

(2) feed data and run graph(operation) : sess.run(op)

(3) update variables in the graph(and return values)

	sess = tf.Session()
    print("sess.run(node1, node2): ", sess.run([node1, node2]))
    print("sess.run(node3): ", sess.run(node3))
    
    sess.run(node1, node2): [3.0, 4.0]
    sess.run(node3) : 7.0

결과값을 출력할려면 세션을 실행시킨 후 run을 이용해서 결과값을 출력한다.

Placeholder

	a = tf.placeholder(tf.float32)
    b = tf.placeholder(tf.float32)
    adder_node = a + b # + provides a shortcut for tf.add(a, b)
    
    print(sess.run(adder_node, feed_dict={a: 3, b: 4.5}))
    print(sess.run(adder_node, feed_dict={a: [1, 3], b: [2, 4]}))
    
    7.5
    [ 3.  7.] 

TensorFlow Mechanics

  1. 그래프를 정의한다. 그래프를 정의 할때 Placeholder라는 노드를 만들 수 있고
  2. 세션을 통해서 그래프를 실행시킬때 feed_dict로 값을 넘겨준다.
  3. 이 그래프가 실행이 되면서 필요한것들을 업데이트 시키거나 내부 variables을 업데이트 시키거나 어떤 출력값을 리턴해준다.

Everything is Tensor

Tensor은 기본적으로 [1. , 2. , 3.] 같은 Array이다.

Tensor Ranks Shapes, and Types

1차원 Array , 2차원 Array .... 등등 n차원 Array다

Shape는 기본적으로 [] 사용한다

data type은 텐서에서 대부분의 경우에는 float32나 int32을 많이 사용한다

0개의 댓글