Categories
Misc

Gradients do not exist warning

I’ve tried to implement Yolov3 network by tf.keras, making it layer-by-layer. Then, I get outputs of layers 82, 94, 106, and pass them (and also – three training inputs with ground truth bounding boxes for every network stride) into Lambda layer to evaluate loss of net. However, when I try to train the network, I receive the warning: “WARNING:tensorflow:Gradients do not exist for variables [‘Layer_Conv_81/kernel:0’, ‘Layer_Conv_91/kernel:0’, ‘Layer_Batch_81/gamma:0’, ‘Layer_Batch_81/beta:0’, ‘Layer_Batch_91/gamma:0’, ‘Layer_Batch_91/beta:0’, ‘Output_1/kernel:0’, ‘Output_2/kernel:0’] when minimizing the loss. If you’re using `model.compile()`, did you forget to provide a `loss`argument?”

I’ve checked the sequence of layers – there are no unconnected ones, I have the loss function. What else could go wrong?

Brief version of code here:

def MakeYoloMainStructure(): inputImage = Input(shape=(IMAGE_SIDES[0], IMAGE_SIDES[1], 3), name='Main_Input') # Start placing layers layer1_1 = Conv2D(32, (3,3), strides=(1,1), use_bias=False, padding='same', name='Layer_Conv_1')(inputImage) layer1_2 = BatchNormalization(epsilon=eps, name='Layer_Batch_1')(layer1_1) layer1_3 = LeakyReLU(alpha=alp, name='Layer_Leaky_1')(layer1_2) # Start placing adding layers # Layer 1 - 64/1 layer2_1 = ZeroPadding2D(((1,0),(1,0)), name='Layer_ZeroPad_2')(layer1_3) layer2_2 = Conv2D(64, (3,3), strides=(2,2), use_bias=False, padding='valid', name='Layer_Conv_2')(layer2_1) layer2_3 = BatchNormalization(epsilon=eps, name='Layer_Batch_2')(layer2_2) layer2_4 = LeakyReLU(alpha=alp, name='Layer_Leaky_2')(layer2_3) ... layer80_2 = BatchNormalization(epsilon=eps, name='Layer_Batch_80')(layer80_1) layer80_3 = LeakyReLU(alpha=alp, name='Layer_Leaky_80')(layer80_2) layer81_1 = Conv2D(1024, (3,3), strides=(1,1), use_bias=False, padding='same', name='Layer_Conv_81')(layer80_3) # From this layer we make fork for first output (!) layer81_2 = BatchNormalization(epsilon=eps, name='Layer_Batch_81')(layer81_1) layer81_3 = LeakyReLU(alpha=alp, name='Layer_Leaky_81')(layer81_2) layer82_1 = Conv2D(3*6, (1,1), strides=(1,1), use_bias=False, padding='same', name='Output_1')(layer81_3) # FIRST output layer (!) layer84_1 = layer80_3 layer85_1 = Conv2D(256, (1,1), strides=(1,1), use_bias=False, padding='same', name='Layer_Conv_83')(layer84_1) ..... layer106_1 = Conv2D(3*6, (1,1), strides=(1,1), use_bias=False, padding='same', name='Output_3')(layer105_3) # THIRD output layer (!) # Net structure is completed yoloBoneModel = Model(inputImage, [layer82_1, layer94_1, layer106_1]) return yoloBoneModel def MakeYoloTrainStructure(yoloBoneModel): gridInput_all = [Input(shape=(GRID_SIDES[1], GRID_SIDES[1], 3, 6), name='Grid_Input_1'), Input(shape=(GRID_SIDES[2], GRID_SIDES[2], 3, 6), name='Grid_Input_2'), Input(shape=(GRID_SIDES[3], GRID_SIDES[3], 3, 6), name='Grid_Input_3')] layer_loss = Lambda(GetLoss, output_shape=(1,), name='GetLoss', arguments={'threshold': thresh})([*yoloBoneModel.output, *gridInput_all]) yoloTrainModel = Model([yoloBoneModel.input, *gridInput_all], layer_loss) return yoloTrainModel def GetLoss(args, threshold=0.5): modelOutputs = args[:3] checkInputs = args[3:] # ...... # Numerous manipulations to get loss of objects detection # ...... return loss def GetDataGenerator(batches): # Here I get image and ground truth Bounding Boxes data yield [imageData, *trueBoxes], np.zeros(batches) def main(): boneModel = MakeYoloMainStructure() trainModel = MakeYoloTrainStructure(boneModel) trainModel.compile(optimizer=Adam(lr=1e-3), loss={'GetLoss': lambda gridInput_all, y_pred: y_pred}, run_eagerly=True) batchSize = 32 trainModel.fit(GetDataGenerator(batchSize), steps_per_epoch=2000//batchSize, epochs=50, initial_epoch=0) 

submitted by /u/Nymfeparakit
[visit reddit] [comments]

Leave a Reply

Your email address will not be published.