0
votes

I have below code, I do not understand why this is graph disconnected error? I do not know what is wrong.

def create_model_tl_attn_posInputOnly(input_shape):
    print("start creating model - transfer learning ...")

    emb = embed_encoding2d(input_shape[0], input_shape[1], input_shape[2]) # this is from another class

    img_input = Input(shape=input_shape)
    base_model = vgg19.VGG19(include_top=False, input_shape=input_shape, weights="imagenet")
    base_model.trainable = False
    x = base_model(img_input + emb)
    
    flat1 = Flatten()(x)
    class1 = Dense(1024, activation='relu')(flat1)
    dropout1 = Dropout(0.2)(class1)
    class2 = Dense(512, activation='relu')(dropout1)
    dropout2 = Dropout(0.2)(class2)
    
    output = Dense(num_classes, activation='softmax')(dropout2) 
    
    model = Model(inputs=img_input, outputs=output)
    
    return model

I changed to model = Model(inputs=base_model.inputs, outputs=output), but still got graph disconnected error.

1
x = base_model(img_input + emb]) seems like there's a typo. Also what was your intention by adding them?Frightera
@Frightera, yes there is a typo, correct the typo still "graph disconnected" error. My intention is to adding img_input and emb. I worked out code as below, however, do not know how to verify if input is the sum of img_input and emb. Thank you.Ling

1 Answers

0
votes

I update code as below, no error, however I do not know if the input is a sum of img_input and emb, how to check during training?

def create_model_tl_attn_posInputOnly(input_shape):
    print("start creating model - transfer learning ...")

    emb = embed_encoding2d(input_shape[0], input_shape[1], input_shape[2]) # this is from another class

    img_input = Input(shape=input_shape)
    base_model = vgg19.VGG19(include_top=False, input_shape=input_shape, weights="imagenet")
    base_model.trainable = False
    x = base_model(img_input + emb)
    x = base_model.layers[-1].output

    flat1 = Flatten()(x)
    class1 = Dense(1024, activation='relu')(flat1)
    dropout1 = Dropout(0.2)(class1)
    class2 = Dense(512, activation='relu')(dropout1)
    dropout2 = Dropout(0.2)(class2)
    
    output = Dense(num_classes, activation='softmax')(dropout2) 
    
    model = Model(inputs=base_model.inputs, outputs=output)
    
    return model