2017-03-28 3 views
3

Keras 2로 업그레이드 한 이후 ResNet50을 미세 조정하려고 할 때 난 손실이 발생합니다. resnet 대신에 하나의 convolutional layer (아래 주석 처리 된)를 사용하면 손실과 정확성이 좋아 보인다. Keras 2로 변경된 사항이 누락 되었습니까?ResNet50 nan with Keras 2

____________________________________________________________________________________________________ 
Layer (type)      Output Shape   Param #  Connected to 
==================================================================================================== 
input_image (InputLayer)   (32, 224, 224, 3)  0 
____________________________________________________________________________________________________ 
zero_padding2d_1 (ZeroPadding2D) (32, 230, 230, 3)  0 
____________________________________________________________________________________________________ 
conv1 (Conv2D)     (32, 112, 112, 64) 9472 

... 

avg_pool (AveragePooling2D)  (32, 1, 1, 2048)  0 
____________________________________________________________________________________________________ 
flatten_1 (Flatten)    (32, 2048)   0 
____________________________________________________________________________________________________ 
dense_1 (Dense)     (32, 2)    4098 
==================================================================================================== 

교육의 출력은 다음과 같습니다 : 같은

from keras.applications.resnet50 import ResNet50 
from keras.layers import Flatten, Dense, Input, Conv2D, Activation, Flatten 
from keras.layers.pooling import MaxPooling2D 
from keras.models import Model 
from keras.optimizers import SGD 
import numpy as np 

inp = Input(batch_shape=(32, 224, 224, 3), name='input_image') 

### resnet 
modelres = ResNet50(weights="imagenet", include_top=False, input_tensor=inp) 
x = modelres.output 
x = Flatten()(x) 

### single convolutional layer 
#x = Conv2D(32, (3,3))(inp) 
#x = Activation('relu')(x) 
#x = MaxPooling2D(pool_size=(3,3))(x) 
#x = Flatten()(x) 
#x = Dense(units=32)(x) 
predictions = Dense(units=2, kernel_initializer="he_normal", activation="softmax")(x) 

model = Model(inputs=inp, outputs=predictions) 
model.compile(SGD(lr=.001, momentum=0.9), "categorical_crossentropy", metrics=["accuracy"]) 

# generate images of all ones with the same label 
def gen(): 
    while True: 
     x_data = np.ones((32,224,224,3)).astype('float32') 
     y_data = np.zeros((32,2)).astype('float32') 
     y_data[:,1]=1.0 
     yield x_data, y_data 

model.fit_generator(gen(), 10, validation_data=gen(), validation_steps=1) 

시작과 model.summary()의 끝이 보인다 내가 대신 theano의 tensorflow하는 백엔드를 전환 할 때

Epoch 1/1 
10/10 [==============================] - 30s - loss: nan - acc: 0.0000e+00 - val_loss: nan - val_acc: 0.0000e+00 
+0

처음부터 또는 일부 일괄/신기원 이후에이 나노가 나타 납니까? –

+0

처음부터 –

+0

입력 한 크기는 얼마입니까? –

답변

2

모든 것이 잘 작동합니다. thean 구현에 대한 무언가가 케라 2에서 깨진 것처럼 보입니다.