InvalidArgumentError Traceback (most recent call last) <ipython-input-115-cbd8dbea3c23> in <module>

Viewed 2946

I am getting the following error and I believe it has something to do with my custom loss function and batch size. I'm not exactly sure how to go about fixing this issue:

InvalidArgumentErrorncompatible shapes: [32,3] vs. [7541,3]
     [[node metrics_28/profit_loss_metric/mul (defined at /Users/neil/opt/anaconda3/lib/python3.7/site-packages/tensorflow_core/python/framework/ops.py:1751) ]] [Op:__inference_keras_scratch_graph_20611]

Function call stack: keras_scratch_graph

    def profit_loss_metric(y_true,y_pred):
        odds = keras_train_odds_final
        eval = ((y_pred + y_true - 1) * (y_pred + y_true) / 2 * odds) - (K.abs(2*(y_pred)-(y_true))-1)*K.abs(2*(y_pred)-(y_true))/2
        eval = K.sum(eval)
        
        return eval
    
    def profit_loss_neil(y_true,y_pred):
        odds = keras_train_odds_final
        loss = ((y_pred + y_true - 1) * (y_pred + y_true) / 2 * odds * -1) + (K.abs(2*(y_pred)-(y_true))-1)*K.abs(2*(y_pred)-(y_true))/2
        loss = K.sum(loss)
        
        return loss
        
    n_cols = features_array.shape[1]
    
    model = Sequential()
    model.add(Dense(1000, activation='relu', input_shape=(n_cols,)))
    model.add(Dense(500, activation='relu', input_shape=(n_cols,)))
    model.add(Dense(3, activation='linear'))
    model.compile(optimizer='Nadam', loss = profit_loss_neil, metrics=[profit_loss_metric])    
    model.fit(features_array,winning_results_final, validation_split = 0.10, epochs=5, shuffle=True )    
1 Answers

The error is because of the incorrect ordering of the arguments. I received this error for an assignment in which the incorrect ordering was

box_confidence, box_xy, box_wh, box_class_probs = yolo_outputs

and correcet ordering was

box_xy, box_wh, box_class_probs, box_confidence = yolo_outputs

Related