Can not squeeze dim[1], expected a dimension of 1, got 2

后端 未结 2 1520
情话喂你
情话喂你 2020-12-21 03:34

I have very simple input: Points, and I am trying to classify whether they are in some region or not. So my training data is of the shape (1000000, 2), which is

相关标签:
2条回答
  • 2020-12-21 04:10

    Your labels are of the wrong shape. See the documentation:

    When using the sparse_categorical_crossentropy loss, your targets should be integer targets. If you have categorical targets, you should use categorical_crossentropy

    So you need to convert your labels to integers:

    train_labels = np.argmax(train_labels, axis=1)
    
    0 讨论(0)
  • 2020-12-21 04:11

    Per your description of the problem, it seems to be a binary classification task (i.e. inside-region vs. out-of-region). Therefore, you can do the followings:

    1. Use 'sigmoid' as the activation function of last layer.
    2. Use one unit (instead of 2) in the last layer.
    3. Use 'binary_crossentropy' as the loss function.

    You also need to map your current labels, i.e. [1,0] and [0,1], to 0s and 1s.

    0 讨论(0)
提交回复
热议问题