나는 당신이 필요에 따라이 옵션이 있습니다 생각합니다. 이 경우 2 개의 출력으로 네트워크를 학습 할 수 있습니다. 여기에 귀하의 게시물에서 파생 예 : 다중 입력 다중 출력 모델 다음 .fit 및 .predict를 들어
input_shape = [3, 20]
inputs = Input(shape=input_shape)
x = Flatten()(inputs)
predictions_1 = Dense(4, name='predictions_1')(x)
# here the predictions_1 just corresponds to your next layer's input
y = Dense(5)(predictions_1)
y = Dense(2)(y)
predictions_2 = Dense(29, name='predictions_2')(y)
# you specify here that you have 2 outputs
model = Model(input=inputs, output=[predictions_1, predictions_2])
, 당신은 https://keras.io/getting-started/functional-api-guide/ 섹션에서 자세한 내용을 많이 찾을 수 있습니다.
(b) 예측에만 관심이있는 경우는입니다. 이 경우에, 당신은 다만 할 수 있습니다
input_shape = [3, 20]
inputs = Input(shape=input_shape)
x = Flatten()(inputs)
predictions_1 = Dense(4, name='predictions_1')(x)
# here the predictions_1 just corresponds to your next layer's input
y = Dense(5)(predictions_1)
y = Dense(2)(y)
predictions_2 = Dense(29, name='predictions_2')(y)
# you specify here that your only output is predictions_2
model = Model(input=inputs, output=predictions_2)
지금 inception_v3에 관하여. 건축물을 사용자가 직접 정의하고 필요에 따라 깊은 층을 수정할 수 있습니다 (이 층에 특정 이름을 지정하면 Keras가 자동으로 이름을 지정하지 않습니다).
는 그 후,이 문제를 해결해야
# you can load weights for only the part that corresponds to the true
# inception_v3 architecture. The other part will be initialized
# randomly
model.load_weights("inception_v3.hdf5", by_name=True)
(https://keras.io/models/about-keras-models/ 참조 기능 load_weights (..., by_name = 참)에서와 같이) 모델로드 가중치를 컴파일합니다. 그런데 추가 정보는 https://www.gradientzoo.com에서 확인할 수 있습니다. 박사.여러 저장 /로드/미세 조정 루틴 설명)
업데이트을 :
input_shape = [3, 20]
# define model1 and model2 as you want
inputs1 = Input(shape=input_shape)
x = Flatten()(inputs1)
predictions_1 = Dense(4, name='predictions_1')(x)
model1 = Model(input=inputs1, output=predictions_1)
inputs2 = Input(shape=(4,))
y = Dense(5)(inputs2)
y = Dense(2)(y)
predictions_2 = Dense(29, name='predictions_2')(y)
model2 = Model(input=inputs2, output=predictions_2)
# then define functions returning the image of an input through model1 or model2
def give_model1():
def f(x):
return model1(x)
return f
def give_model2():
def g(x):
return model2(x)
return g
# now you can create a global model as follows:
inputs = Input(shape=input_shape)
x = model1(inputs)
predictions = model2(x)
model = Model(input=inputs, output=predictions)
감사합니다. 이 작업은 전체 시작 모델을 재정의하려는 경우에 유용합니다. 하지만 이미'Model' 객체를 가지고 있다면 어떻게 될까요? 처음부터 다시 정의 할 필요없이 새로운 모델에 직접 부착 할 수있는 방법이 있는지 궁금합니다 (매우 큰 모델이라고 생각할 때). 또한 링크 덕분에 – meto
@meto 나는 그것을 얻는다. 귀하의 의견과 Omid의 제안을 바탕으로 방금 답변을 업데이트했습니다. 너에게 효과가 있니? – bn2nkm