2

I have seen a few people with similar errors, but none seem to pertain to me and as someone who is relatively new to python it's all a bit confusing.

I'm using Tensorflow + TFLearn to try and make a very simple network that can predict the price of avocados given the type, place of origin, and year (Don't ask), and It keeps throwing the error:

Cannot feed value of shape (10, 500) for Tensor 'TargetsData/Y:0', which has shape '(?, 1)'

I have n_class set to 500 because I'm working with some higher numbers and it kept throwing an error if it was too low, but from what I understand it isn't that, it is something to do with the "shape", but I don't really know what that means.

I'll paste in my full code, sorry if this is a bad question/a simple question, I'm just new to all this and a bit confused.

data, labels = tflearn.data_utils.load_csv('avocado.csv',
                                               target_column=2,
                                               categorical_labels=True,
                                               n_classes=500,
                                               columns_to_ignore=[0,1,3,4,5,6,7,8,9,10])
    for type in data:
        if type[0] == "conventional":
            type[0] = 1
        else:
            type[0] = 0

    for place in data:
        if place[2] == "Albany":
            place[2] = 0
        elif place[2] == "Atlanta":
            place[2] = 1
        elif place[2] == "BaltimoreWashington":
            place[2] = 2
        elif place[2] == "Boise":
            place[2] = 3
        elif place[2] == "Boston":
            place[2] = 4
        elif place[2] == "BuffaloRochester":
            place[2] = 5
        elif place[2] == "California":
            place[2] = 6
        elif place[2] == "Charlotte":
            place[2] = 7

    #this goes on for a while, just converting strings to int to work 
    #with TFLearn

    print(data[0])
    # define the input layer
    # 3 because we have 3 columns in the data set (year, location, and type)
    net = tflearn.input_data(shape=[None, 3])

    # adding hidden layers
    net = tflearn.fully_connected(net, 32)
    net = tflearn.fully_connected(net, 32)

    # the output layer
    net = tflearn.fully_connected(net, 1, activation="softmax")

    net = tflearn.regression(net)

    # define model
    model = tflearn.DNN(net)

    # start training
    model.fit(data, labels, n_epoch=10, batch_size=10, show_metric=True)

Thanks in advance for any help, and again sorry if this is a stupid question.

1 Answer 1

0

Your example code along with the problem description seems to be about regression, however you've set categorical_labels=True and along with n_classes=500 this will treat the avocado price as a categorical variable with 500 different possible values (instead of a continuous variable). This creates 500 class one-hot vectors which is incompatible with the last layer of your network (which has one output node instead of 500). For your regression problem you should set categorical_labels=False and you can leave out n_classes at all.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.