1 of 44

Soo Kyung Kim

Department of AI

AI IoT (AI Programming)� �- Course Introduction

  • Intro of conda environment

2 of 44

What is AI?

3 of 44

What is Machine Learning?

4 of 44

What is Deep Learning?

5 of 44

What is Deep Learning?�: State-of-the-art performance

6 of 44

What is Deep Learning?�

7 of 44

What is Deep Learning?�

8 of 44

How is this Possible?

9 of 44

How is this Possible?

10 of 44

Modern AI

11 of 44

(Almost) Infinite Compute + (Almost) Infinite Data

12 of 44

Large Language Models (LLMs)

13 of 44

DALL-E 2, Imagen, Stable Diffusion

14 of 44

AlphaFold2

15 of 44

Transformer Architecture

16 of 44

Weekly Plan

17 of 44

Installing Conda

  • Conda: Virtual Environment
  • OS: Window, Mac, Linux

18 of 44

What's Tensorflow?

  • Open-source software library for numerical computation using data flow graphs
  • Flexibility + ScalabilityOriginally developed by Google as a single infrastructure for machine learning in both production and research
  • Tensorflow VS Pytorch

19 of 44

Install Tensorflow – Virtual environment

  • Python3, terminal (OS: mac, window, linux etc)
  • Virtual environment
    • Python virtual environment

    • Conda virtual environment
      • Install Conda:  Go to https://docs.conda.io/en/latest/miniconda.htmlThen download proper installer for your OS��  bash [proper installer] 
      • Create Environment

https://www.tensorflow.org/install

python3 -m venv venv3 # Create a Python 3 virtual environment source source ./venv3/bin/activate # Activate the virtual environment

pip install --upgrade pip

Pip install tensorflow jupyterlab numpy

conda create -n myenv python=3.10

conda activate myenv

conda install tensorflow jupyterlab numpy

conda deactivate

  • conda env list.  OR   conda env list.  # List environemnt
  • conda remove -n ENV_NAME –-all # delete environment.

export PATH="/Users/sookim/miniconda3/bin:$PATH"

20 of 44

Data Flow Graphs

  • Phase 1: assemble a graph
  • Phase 2: Flow data (tensor)    (tensorflow 1.x) use a session to execute operations in the graph

21 of 44

Data Flow Graphs

  • Tensorflow separates definition of computations from their execution

22 of 44

What is a Tensor?

  • An N-dimensional array
    • 0-d Tensor: scalar (number)
    • 1-d Tensor: vector
    • 2-d Tensor: matrix
    • 3-d Tensor: Tensor

And so on

23 of 44

Data Flow Graphs

import tensorflow as tf

a = tf.add(3, 5)

Why x, y?

TF automatically names the nodes when you don’t explicitly name them. 

x = 3

y = 5

24 of 44

Data Flow Graphs

import tensorflow as tf

a = tf.add(3, 5)

Nodes: operators, variables, and constantsEdges: tensors��Tensors are data.

TensorFlow = tensor + flow 

     = data + flow 

25 of 44

Data Flow Graphs

import tensorflow as tf

a = tf.add(3, 5)

Print(a)�

>> Tensor("Add:0", shape=(), dtype=int32)

(Not 8)

26 of 44

Data Flow Graphs

import tensorflow as tf

a = tf.add(3, 5)

Print(a.numpy())

>> 8

27 of 44

More Graph

x = 2y = 3op1 = tf.add(x, y)op2 = tf.multiply(x, y)op3 = tf.pow(op2, op1)

import tensorboard

%tensorboard --logdir logs/func

28 of 44

Okay! Let's get into deeper now. 

29 of 44

Tensorflow 1.x vs Tensorflow 2.x�- TF1: Build a graph, then run it in session.

conda config --set subdir osx-64 # if you are a mac unser using M1,2 Apple silicon

conda create --name tf1.4 python=3.6

conda activate tf1.4

pip install tensorflow==1.4

pip install  jupyterlab numpy

**conda env remove tf1.4 # REMOVE environment�

30 of 44

Tensorflow 1.x vs Tensorflow 2.x�- TF1: Build a graph, then run it in session.

31 of 44

Tensorflow 1.x vs Tensorflow 2.x�- TF2 : You can check node before session

conda create --name tf tensorflow

pip install  jupyterlab numpy�

32 of 44

Tensorflow 1.x vs Tensorflow 2.x�- TF2 : You can check node before session

33 of 44

Tensorflow 1.x vs Tensorflow 2.x�- TF2 : Keras is built-in to TF2

34 of 44

Tensorflow 1.x vs Tensorflow 2.x�- TF2 : You can explore layers interactively

35 of 44

TF2: Three Model building styles�- Sequential, Functional, Subclassing

36 of 44

Sequential Model

37 of 44

Functional Model

38 of 44

Sequential Model

39 of 44

TF2: Two training approaches�- Built-in and Custom

40 of 44

Built-in

41 of 44

Custom (define your own)

42 of 44

Tensorboard

import tensorboard

%tensorboard --logdir logs/func

43 of 44

# Load the TensorBoard notebook extension�%load_ext tensorboard�import tensorflow as tf�import datetime��mnist = tf.keras.datasets.mnist��(x_train, y_train), (x_test, y_test) = mnist.load_data()�x_train, x_test = x_train / 255.0, x_test / 255.0��model = tf.keras.models.Sequential([� tf.keras.layers.Flatten(input_shape=(28, 28), name='layers_flatten'),� tf.keras.layers.Dense(512, activation='relu', name='layers_dense'),� tf.keras.layers.Dropout(0.2, name='layers_dropout'),� tf.keras.layers.Dense(10, activation='softmax', name='layers_dense_2')� ])��model.compile(optimizer='adam',� loss='sparse_categorical_crossentropy',� metrics=['accuracy'])��log_dir = "logs/fit/" + datetime.datetime.now().strftime("%Y%m%d-%H%M%S")�tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir=log_dir, histogram_freq=1)��model.fit(x=x_train, � y=y_train, � epochs=5, � validation_data=(x_test, y_test), � callbacks=[tensorboard_callback])�%tensorboard --logdir logs/fit

https://www.tensorflow.org/tutorials/quickstart/beginner

Do simple Mnist example

https://github.com/fastscience-ai/�Ewha/tree/main/lab

CODE

44 of 44

Next Class?

  • Project Overview (+KCI paper)
  • Numpy