2017-12-10 16 views
1

동일한 가중치를 어느 정도 동일한 2 개의 동일한 분기를 구현하려고합니다. 여기에서 볼 수있는 그래픽 enter image description here은 내가 가지고있는 단순화 된 모델입니다. 그래서 저는 입력이 있습니다 : 음수와 양수, conv1_1_x부터 Rpn까지의 모든 레이어는 같은 가중치를 가져야합니다. 내가 지금까지 구현하려고 노력하는 것입니다 :Theano의 Keras에서 같은 가중치를 공유하는 레이어 2 개를 동일한 방법으로 구현하는 방법

def create_base_network(input_shape, branch, input_im, img_input, roi_input): 
      def creat_conv_model(input_shape): 
       branch = Sequential() 
       branch.add(Conv2D(64,filter_size,subsample = strides, input_shape=input_shape , activation='relu',kernel_initializer='glorot_uniform' ,name='conv1_1_'+str(branch))) 
       branch.add(Conv2D(64,filter_size, subsample = strides, activation='relu', kernel_initializer='glorot_uniform',name='conv1_2_1'+str(branch))) 
       branch.add(MaxPooling2D(pool_size=(2,2), strides=pool_stride, name='pool1_'+str(branch))) 
       branch.add(Conv2D(128,filter_size,subsample = strides, activation='relu', kernel_initializer='glorot_uniform',name='conv2_1_'+str(branch))) 

       return branch 
      shared_layers = creat_conv_model(input_shape) 
      rpn_output = rpn(shared_layers(input_im),9,branch) 
      model = Model([img_input, roi_input], rpn_output[:2]) 

      return model 


Branch_left = create_base_network((64, 64, 3), 1, img_input_left, img_input, roi_input) 
Branch_right = create_base_network((64, 64, 3), 2, img_input_right, img_input, roi_input)  

내가 이것을 실행, 나는 다음과 같은 오류 얻을 :

RuntimeError: Graph disconnected: cannot obtain value for tensor /input_2 at layer "input_2". The following previous layers were accessed without issue: [] 

사람이 도와 드릴까요?

+0

두 개가 동일하고 동일한 입력을 사용하는 이유는 무엇입니까? –

+0

입력은 2 개의 다른 이미지가됩니다. 1 개의 음수 입력과 1 개의 양수 입력. 새로운 구현으로 내 질문을 편집했습니다. 이 경우 가중치가 실제로 공유되는지 확인해주십시오. – Tassou

답변

0

가중치를 공유하는 모델의 경우 한 번만 만들어야합니다. 두 개의 모델을 만들 수는 없습니다. 모델 branch_left 생성 정보

img_neg_out = shared_model(img_input_left) 
img_neg_out = rpn_model(img_neg_out) 

img_pos_out = shared_model(img_input_right) 
img_pos_out = rpn_model(img_pos_out) 

:

rpn_model = create_rpn(...) 

는 그런 다음 입력을 전달합니다 rpn 만약

shared_model = creat_conv_model((64, 64, 3), left) 

당신이 그것을 한 번만 작성해야합니다, 또한 공유 할 수있는 모델입니다 그리고 branch_right, 당신이하고 싶은 일과 훈련 방법에 달려 있습니다.

+0

안녕하세요, 기여해 주셔서 감사합니다. 내 편집을 봤어? 이게 내가하는 일이 아닌가? 아니면 내가 이름 = 'conv1_2_1'+ str (brh)에 따라 레이어의 이름을 변경한다는 사실은 lleft의 경우 brh = 1이고 오른쪽의 경우 2는 로직을 깰 수 있습니까? – Tassou

+0

아니요, 두 가지 모델을 만들고 있습니다. 그들은 무게를 공유하지 않습니다. –

+0

실제로 처음부터 입력을 받아 들여 기능적 API 모델을 사용하여이 작업을 수행 할 수 있습니까? – Tassou