반응형
tf.nn.conv2d
- input
입력 데이터의 형태
(이미지 개수, 이미지 height, 이미지 width, channel) - filter
필터의 형태
(필터 height, 필터 width, channel, 필터의 개수) - stride
길이가 1, 2 또는 4인 정수 리스트 - padding
- 'SAME' : convolution 결과가 원본 이미지 크기와 같음
- 'VAILD' : zero padding
다른 옵션들
tf.nn.conv2d | TensorFlow Core v1.15.0
tf.nn.conv2d Computes a 2-D convolution given 4-D input and filter tensors. View aliases Compat aliases for migration See Migration guide for more details. tf.compat.v1.nn.conv2d tf.nn.conv2d( input, filter=None, strides=None, padding=None, use_cudnn_on_gp
www.tensorflow.org
예시
# channel이 3인 이미지 데이터를 convolution 연산하는 코드
import numpy as np
import tensorflow as tf
sample = np.array([[[[1,2,3],
[1,2,3],
[1,2,3]], # channel 1
[[1,2,3],
[1,2,3],
[1,2,3]], # channel 2
[[1,2,3],
[1,2,3],
[1,2,3]]]], dtype=np.float64) # channel 3
print(sample.shape)
(1, 3, 3, 3)
filter = np.array([[[[0, 1],
[1, 0],
[1, 0]],
[[0, 1],
[1, 0],
[1, 0]]],
[[[0, 1],
[1, 0],
[1, 0]],
[[0, 1],
[1, 0],
[1, 0]]]], dtype=np.float64)
print(filter.shape)
(2, 2, 3, 2)
conv2d = tf.nn.conv2d(sample, filter, strides=[1,1,1,1], padding='VALID', )
sess = tf.Session()
sess.run(conv2d)
array([[[[20., 4.], [20., 4.]], [[20., 4.], [20., 4.]]]])
반응형
'Programming > Tensorflow' 카테고리의 다른 글
[tensorflow] multi-output model 데이터 입력 : flow_from_dataframe (0) | 2022.07.05 |
---|---|
[Tensorflow 1.15] 이미지 Convolution, Pooling의 결과 확인하기 (0) | 2022.04.14 |
[Tensorflow] MNIST DNN으로 구현해보기 (0) | 2022.04.12 |
[Tensorflow] 학습한 모델 저장하기 (0) | 2022.04.07 |
[Tensorflow] Tensorflow 2.xx with Keras (0) | 2022.04.07 |