Introduction to TensorFlow for Artificial Intelligence, Machine Learning, and Deep Learning week3

han811·2020년 11월 8일
0
post-thumbnail

fashion_mnist를 좀더 maxpooling과 conv2d로 학습시키는 과정이다.

tf.keras.models계열은 compile을 해준 후에 summary()메서드를 호출하면 네트워크의 구조를 파라미터와 함께 파악할 수 있다.

import matplotlib.pyplot as plt
f, axarr = plt.subplots(3,4)
FIRST_IMAGE=0
SECOND_IMAGE=7
THIRD_IMAGE=26
CONVOLUTION_NUMBER = 1
from tensorflow.keras import models
layer_outputs = [layer.output for layer in model.layers]
activation_model = tf.keras.models.Model(inputs = model.input, outputs = layer_outputs)
for x in range(0,4):
  f1 = activation_model.predict(test_images[FIRST_IMAGE].reshape(1, 28, 28, 1))[x]
  axarr[0,x].imshow(f1[0, : , :, CONVOLUTION_NUMBER], cmap='inferno')
  axarr[0,x].grid(False)
  f2 = activation_model.predict(test_images[SECOND_IMAGE].reshape(1, 28, 28, 1))[x]
  axarr[1,x].imshow(f2[0, : , :, CONVOLUTION_NUMBER], cmap='inferno')
  axarr[1,x].grid(False)
  f3 = activation_model.predict(test_images[THIRD_IMAGE].reshape(1, 28, 28, 1))[x]
  axarr[2,x].imshow(f3[0, : , :, CONVOLUTION_NUMBER], cmap='inferno')
  axarr[2,x].grid(False)

프레임워크 사용법에 있어서 유의미 했던 부분은 tf.keras.models계열의 클래스들은 model.layers로 각 layer에 접근이 가능하며 각 layer에는 output 멤버변수를 호출하면 각 layer를 통과한 값이 나오게 된다.
이를 tf.keras.models.Model클래스를 통해 inputs와 outputs로 동적으로 선언해준 모습이다.

https://github.com/han811/tensorflow

profile
han811

0개의 댓글