본문 바로가기

전체 글687

[Tensorflow] 4. MNIST 모델 학습 및 예측 모델(model)이 예측(logit)하고 얼마나 틀렸는지(loss) 계산하고 그걸 최적화(Optm)하고 최적화한 loss를 모델에 적용하고 이를 지정한 횟수만큼 반복해서 그 결과를 result에 출력 In [1]: import tensorflow as tf import matplotlib.pyplot as plt %matplotlib inline from tensorflow.keras import layers import numpy as np from tensorflow.keras import datasets 모델을 학습하기 전 설정(Optimization)¶ Loss Function Optimization(최적화 방법 정하기) Metrics(결과 테스트 방법) Categorical vs Binary¶ .. 2021. 6. 22.
[Matplotlib] 번외. matplotpib 한글폰트 깨짐 해결 In [3]: import matplotlib.font_manager as fm font_list = fm.findSystemFonts(fontpaths = None, fontext = 'ttf') font_list[:] import matplotlib as mpl In [5]: print (mpl.matplotlib_fname()) #matplotlibrc 파일을 메모장을 열어준다 C:\Users\choi\Anaconda3\lib\site-packages\matplotlib\mpl-data\matplotlibrc In [6]: # font.family : sans-serif을 font.family : 변경할폰트명 으로 변경해준다 # axes.unicode_minus : True -> Fa.. 2021. 6. 18.
[Numpy,Matplotlib] 4.이미지 시각화도 가능하다 In [1]: import numpy as np import matplotlib as mpl import matplotlib.pyplot as plt import matplotlib.font_manager as fm %matplotlib inline from PIL import Image In [2]: import matplotlib matplotlib.font_manager._rebuild() In [4]: #이미지 파일 열기# path = 'source/dog.jpg' image_pil=Image.open(path) image = np.array(image_pil) In [5]: image_pil Out[5]: In [6]: image.shape #세로,가로,RGB) gray는 1이다... 2021. 6. 18.
[Numpy,Matplotlib] 3.시각화matplotlib.pyplot as plt https://rfriend.tistory.com/408 에 seaborn와 plot 그래프들에 대한 예제가 많이 있음 참조만 할것 In [1]: import numpy as np import matplotlib.pyplot as plt %matplotlib inline In [2]: data = np.random.randn(50).cumsum() data Out[2]: array([-1.70416886, -2.20382106, -2.70563343, -4.28915986, -3.9987641 , -4.24362761, -5.27902219, -8.15694697, -7.9827752 , -7.80333919, -5.88645842, -3.6525847 , -5.13716405, -5.36678818, .. 2021. 6. 18.
[Numpy,Matplotlib] 2.Numpy는 차원을 늘리고 줄일수 있다 In [7]: import numpy as np arr=np.array([[1,2,3],[1,2,3]]) arr.shape Out[7]: (2, 3) In [8]: arr=np.expand_dims(arr,-1) #내부값은 유지하고 차원 수를 늘리고 싶을대 arr #-1을 하면 차원수와 값의 위치가 변경된다 Out[8]: array([[[1], [2], [3]], [[1], [2], [3]]]) In [9]: arr.shape Out[9]: (2, 3, 1) In [10]: #0으로 채워진 np.array zeros = np.zeros([3,3]) zeros Out[10]: array([[0., 0., 0.], [0., 0., 0.], [0., 0., 0.]]) In [11]: zeros=np.zeros.. 2021. 6. 18.
[Numpy,Matplotlib] 1. 배열다루기+시각화의 기초 In [2]: import tensorflow as tf In [3]: tf.__version__ Out[3]: '2.4.1' In [4]: import sys print(sys.version) 3.8.5 (default, Sep 3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)] In [5]: import torch In [6]: torch.rand(10) Out[6]: tensor([0.3455, 0.7188, 0.9561, 0.4839, 0.4847, 0.4576, 0.0298, 0.0426, 0.0475, 0.4781]) In [7]: import numpy as np In [8]: arr = np.array(5) arr.shape Out[8]: () .. 2021. 6. 18.
[Tensorflow] 3.tensorflow에서 레이어가 어떤식으로 동작하는지 In [25]: import tensorflow as tf import matplotlib.pyplot as plt %matplotlib inline import numpy as np In [3]: from tensorflow.keras import datasets (train_x,train_y),(test_x,test_y) = datasets.mnist.load_data() In [4]: #모든 작업을 하기전에 shape로 이미지 인지 문자인지 확인해줘야한다. image=train_x[0] image.shape Out[4]: (28, 28) In [5]: plt.imshow(image,'gray') plt.show() In [6]: image = image[tf.newaxis,...,tf.newaxis.. 2021. 6. 18.
[Tensorflow] 2.Tensorflow기본 DataSet (MNIST) In [1]: import numpy as np import matplotlib.pyplot as plt import tensorflow as tf %matplotlib inline In [2]: #tensorflow에서 제공하는 데이터셋(MNIST) 불러오기 #숫자 그림 데이터다. from tensorflow.keras import datasets In [3]: mnist=datasets.mnist In [4]: (train_x,train_y),(test_x,test_y) = mnist.load_data() Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz 11493376/11490434 .. 2021. 6. 18.
[Tensorflow] 1. Tensorflow의 기본 Tensor In [1]: import numpy as np import tensorflow as tf In [2]: # Tensor 생성 [1,2,3] Out[2]: [1, 2, 3] In [3]: [[1,2,3],[4,5,6]] Out[3]: [[1, 2, 3], [4, 5, 6]] In [4]: arr= np.array([1,2,3]) arr.shape Out[4]: (3,) In [5]: arr=np.array([[1,2,3],[4,5,6]]) arr.shape Out[5]: (2, 3) In [6]: #list와 tensor는 다르다 #list1=[1,2,3] tf.constant([1,2,3]) #tf.constant(list1) Out[6]: In [9]: #Array를 tesnfor로 변경 array=.. 2021. 6. 17.