Pranav Polavarapu
Pranav Polavarapu

Reputation: 21

Invalid Argument Error: Graph Execution Error

My code:

callbacks that will be used during training

early_stopping = EarlyStopping(monitor='val_loss', mode = 'min', patience=10) checkpoint = ModelCheckpoint(filepath = './weights.hdf5', verbose=1, save_best_only=True)\

base_model = Xception(weights="imagenet", include_top=False, input_tensor=Input(shape=(224, 224, 3))) base_model.summary()

for layer in base_model.layers: layer.trainable = False head_model = AveragePooling2D(pool_size=(4, 4))(base_model.output) head_model = Flatten(name='flatten')(head_model) head_model = Dense(1024, activation='relu')(head_model) head_model = Dropout(0.3)(head_model) head_model = Dense(512, activation='relu')(head_model) head_model = Dropout(0.3)(head_model) head_model = Dense(120, activation='softmax')(head_model)

model = Model(inputs=base_model.input, outputs=head_model) optimizer = SGD(learning_rate=0.1, momentum=0.9, decay=0.01) model.compile(loss="categorical_crossentropy", optimizer=optimizer, metrics=["accuracy"])

#first cycle history1 = model.fit(train_generator, epochs=5, callbacks=[checkpoint], validation_data=val_generator)

I get the following Errors:

InvalidArgumentError Traceback (most recent call last) <ipython-input-67-9f6b46dd1195> in <module>() 1 #first cycle 2 ----> 3 history1 = model.fit(train_generator, epochs=5, callbacks=[early_stopping], validation_data=val_generator)

InvalidArgumentError: Graph execution error:

Detected at node 'categorical_crossentropy/softmax_cross_entropy_with_logits' defined at (most recent call last):

The model will be trained in 3 cycles. In the first cycle, only the added classifier's layers to the network "head_model" will be trainable with a relatively high learning rate. During the second cycle, half of the exception model's layers will be unfrozen while in the third cycle all of the layers will be unfrozen. During the second and third cycles, the learning rate of the optimizer will be reduced.

#first cycle

history1 = model.fit(train_generator, epochs=5, validation_data=val_generator, callbacks=[checkpoint])

Getting an error in the first cycle itself...

Upvotes: 1

Views: 2836

Answers (1)

Pranav Polavarapu
Pranav Polavarapu

Reputation: 21

I have found the solution to this problem. There's a problem with the final Dense layer number (output classes). I have changed the value from 120 to 7, as I had 7 output classes; & the epochs are running properly now...

head_model = Dense(120, activation='softmax')(head_model) -> old
head_model = Dense(7, activation='softmax')(head_model) -> edited

Upvotes: 1

Related Questions