Keras에서 tensorflow 함수 사용하기 본문

ML & DL/이것저것..

Keras에서 tensorflow 함수 사용하기

eremo2002 2019. 2. 26. 12:35

케라스를 사용해서 만든 모델은 모두 케라스 레이어로 이루어져 있다. 

만약 중간에 텐서플로우의 레이어를 사용하고자 한다면 텐서플로우 레이어를 케라스의 Lambda 레이어로 감싸주어야 한다.


import numpy as np
import tensorflow as tf
from keras import Input, Model
from keras.layers import Lambda


x = Input((224, 224, 3))
h, w = 299, 299

y = Lambda(lambda inputs: tf.image.resize_bilinear(inputs,
                                                   tf.stack([h, w]),
                                                   align_corners=True))(x)
model = Model(inputs=x, output=y)
model.summary()

p = model.predict(np.random.randn(1, 224, 224, 3))
print('shape:', p.shape)


source 

https://stackoverflow.com/questions/48956407/tensorflow-to-keras-tensor

'ML & DL > 이것저것..' 카테고리의 다른 글

CNN feature visualization  (0) 2019.10.25
RetinaNet을 이용한 Object Detection  (0) 2019.10.23
ResNet50 구현해보기  (4) 2019.01.23
MobileNetV1  (1) 2019.01.16
difference between SeparableConv and DepthwiseConv  (0) 2019.01.15
Comments