Skip to content Skip to sidebar Skip to footer

Can Not Squeeze Dim[1], Expected A Dimension Of 1, Got 5

I tried different solutions but still facing the issue. Actually I am new in Ml/DL (python). In which case we face this error 'Can not squeeze dim1, expected a dimension of 1, got

Solution 1:

Facing this error because I have a total of 5 attributes and each has 3 tags according to the above scenario, We will not face the above error If we encode labels in such a way

defcustom_encode(tags, mapping):
    # create empty vector
    encoding=[]
    for tag in tags:
        if tag == 'L':
            encoding.append([1,0,0])
        elif tag == 'M':
            encoding.append([0,1,0])
        else:
            encoding.append([0,0,1])
    return encoding

and create the final layer like this

model.add(Dense(15)) #because we have total 5 labels and each has 3 tags so 15 neurons will be on final layer
model.add(Reshape((5,3))) # each 5 have further 3 tags we need to reshape it
model.add(Activation('softmax'))

model.compile(optimizer=opt, loss='categorical_crossentropy',
                  metrics=['accuracy'])

Post a Comment for "Can Not Squeeze Dim[1], Expected A Dimension Of 1, Got 5"