ValueError: Can not squeeze dim[1], expected a dimension of 1, got 3 for 'sparse_softmax_cross_entropy_loss

前端 未结 5 705
眼角桃花
眼角桃花 2020-12-09 15:18

I tried to replace the training and validation data with local images. But when running the training code, it came up with the error :

ValueError: Ca

5条回答
  •  我在风中等你
    2020-12-09 15:54

    i write the code that change [1,0,0], [0,1,0], [0,0,1] to 0,1,2.

    import numpy as np
    import tensorflow as tf
    
    def change_to_right(wrong_labels):
        right_labels=[]
        for x in wrong_labels:
            for i in range(0,len(wrong_labels[0])):
                if x[i]==1:
                    right_labels.append(i)
        return right_labels
    
    wrong_labels =np.array([[0,0,1,0], [0,0,1,0], [1,0,0,0],[0,1,0,0]])
    right_labels =tf.convert_to_tensor(np.array(change_to_right(wrong_labels)))
    

提交回复
热议问题