반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- wsl2
- ubuntu
- 머신러닝
- 가상환경
- 파이썬
- pip install
- 가상환경구축
- python 문법
- Deep learning
- __call__
- CNN
- pytorch
- python
- torch.nn.Module
- DeepLearning
- LSTM
- vision transformer
- Torchvision
- torch.nn
- AI
- pychram
- Anaconda
- 딥러닝
- 파이썬문법
- __init__
- docker
- rnn
- ViT
- tensorflow
- objectdetection
Archives
- Today
- Total
인공지능을 좋아하는 곧미남
[tensorflow] .get_shape().as_list() 활용 방법 본문
오늘은 .get_shape().as_list()를 어떻게 제가 활용했는지 확인해보겠습니다.
간단하게 .get_shape()와 .as_list()에 관해 알아보고 딥러닝 모델을 구현할 때 어떻게 사용했는지 설명하겠습니다.
1. .get_shape() 란?
- 행렬, 배열 등의 shape를 출력해주는 함수입니다.
2. .as_list() 란?
- return 되는 값이 list형태로 변환해서 return합니다.
convolution layer shape는 일반적으로 (batch_size, height, width, chennel) 입니다.
아래와 같이 선언해주면, 해당 conv layer의 height와 width shape 값을 얻을 수 있습니다.
- h, w = conv_4_2.get_shape().as_list()[1:3]
저는 이 값을 얻어 crop 할때 사용을 하였는데요. 두 conv layer의 h, w를 얻어 tf.image.crop_to_bounding_box() 함수를 통해 좀 더 알고리즘적인 코드로 원하는 shape을 crop 할 수 있었습니다!
h1_1, w1_1 = conv1.get_shape().as_list()[1:3]
h1_2, w1_2 = conv2.get_shape().as_list()[1:3]
cropping_1 = tf.image.crop_to_bounding_box(image=conv3, offset_height=int(0.5 *(h1_1- h1_2)),
offset_width=int(0.5 *(w1_1 - w1_2)),
target_height = h1_2,
target_width=w1_2)
반응형
Comments