I think Image objects have size attributes and arrays have shape attributes. Try renaming it in your code. (See : http://effbot.org/imagingbook/image.htm)

Answer from Daneel on Stack Overflow
🌐
Hugging Face
discuss.huggingface.co › beginners
Error: AttributeError: 'NoneType' object has no attribute 'shape' when prompt tuning with Chatglm2 - Beginners - Hugging Face Forums
October 9, 2023 - I modified simple code of peft to train chatglm2-6b witn prompt-tuning. Below is my code: from transformers import AutoModelForCausalLM from peft import get_peft_config, get_peft_model, PromptTuningInit, PromptTuningConfig, TaskType, PeftType import torch from datasets import load_dataset import ...
🌐
PyTorch Forums
discuss.pytorch.org › vision
AttributeError: 'Image' object has no attribute 'shape' - vision - PyTorch Forums
April 14, 2022 - I tried to apply RandomErase transform for every images using the following code my_transforms = transforms.Compose([ transforms.Resize((192,192)), transforms.RandomErasing(p=1), transforms.ToTensor(), transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)) ]) dataset = datasets.ImageFolder...
Discussions

AttributeError: 'NoneType' object has no attribute 'shape' - imgcodecs - OpenCV
What is this error?? Traceback (most recent call last): File "code.py", line 1717, in shape height, width = input.shape AttributeError: 'NoneType' object has no attribute 'shape' This is the code: input… More on forum.opencv.org
🌐 forum.opencv.org
0
August 24, 2021
Cannot do inference on a model AttributeError: 'Image' object has no attribute 'shape'. Did you mean: 'save'?
Cannot do inference on a model AttributeError: 'Image' object has no attribute 'shape'. Did you mean: 'save'?#7473 More on github.com
🌐 github.com
35
January 10, 2024
python - the question of 'list' object has no attribute 'shape' - Stack Overflow
File "C:\Users\fan\rssi-filtering-kalman\venv\Lib\site-packages\numpy\core\fromnumeric.py", line 2033, in shape result = a.shape ^^^^^^^ AttributeError: 'list' object has no attribute 'shape' During handling of the above exception, another exception occurred: Traceback (most recent call last): ... More on stackoverflow.com
🌐 stackoverflow.com
I get a weird " 'function object has no attribute 'shape' " for a parameter which is clearly not an object, just a numpy array.
And Y_train is clearly an array Between you and the interpreter, you're the only one who can be wrong about what type a value is. That's just how it is - the state of the interpreter is the ground truth, and you're a human being with a mental model of it. Debugging is almost always the act of figuring out how and where your assumptions depart from reality. More on reddit.com
🌐 r/learnpython
6
1
June 27, 2020
🌐
OpenCV
forum.opencv.org › t › attributeerror-nonetype-object-has-no-attribute-shape › 4910
AttributeError: 'NoneType' object has no attribute 'shape' - imgcodecs - OpenCV
August 24, 2021 - What is this error?? Traceback (most recent call last): File "code.py", line 1717, in shape height, width = input.shape AttributeError: 'NoneType' object has no attribute 'shape' This is the code: input…
🌐
GitHub
github.com › ultralytics › ultralytics › issues › 7473
Cannot do inference on a model AttributeError: 'Image' object has no attribute 'shape'. Did you mean: 'save'? · Issue #7473 · ultralytics/ultralytics
January 10, 2024 - Cannot do inference on a model AttributeError: 'Image' object has no attribute 'shape'. Did you mean: 'save'?#7473
Author   Medkallel
🌐
Bobby Hadz
bobbyhadz.com › blog › python-attributeerror-nonetype-object-has-no-attribute-shape
AttributeError: 'NoneType' object has no attribute 'shape' | bobbyhadz
April 8, 2024 - The Python "AttributeError: 'NoneType' object has no attribute 'shape'" occurs when we access the shape attribute on a None value, e.g.
🌐
Bobby Hadz
bobbyhadz.com › blog › python-attributeerror-list-object-has-no-attribute-shape
AttributeError: 'list' object has no attribute 'shape' | bobbyhadz
April 8, 2024 - The Python AttributeError: 'list' object has no attribute 'shape' occurs when we try to access the `shape` attribute on a list.
Find elsewhere
🌐
Reddit
reddit.com › r/learnpython › i get a weird " 'function object has no attribute 'shape' " for a parameter which is clearly not an object, just a numpy array.
r/learnpython on Reddit: I get a weird " 'function object has no attribute 'shape' " for a parameter which is clearly not an object, just a numpy array.
June 27, 2020 -

I'm implementing a cost function for a neural network, which takes in the predictions made on the training set by the forward propagation step, the true output labels Y, and calculates the cost of the model. The function definition is -

def calculate_cost (Y, prediction, activation_output = 'sigmoid'):
    """
    Calculates the cost.

    Takes in the output labels and the prediction from forward propagation, as well as the activation function of the output layer.
    Returns the cost.
    """
    m = Y.shape[1]

    if activation_output.lower() == 'sigmoid':
        cost = (1/m)*np.sum(Y*np.log(prediction) + (1-Y)*np.log(1-prediction))

    if activation_output.lower() == 'softmax':
        cost = (1/m)*np.sum(np.sum(Y*np.log(prediction), axis = 0, keepdims = True))

    return cost

I get an error on the line where I declare m as the second dimension of the input parameter Y.

<ipython-input-6-0c38b0031612> in calculate_cost(Y, prediction, activation_output)     
     10     """
---> 11     m = Y.shape[1]
     12 
     13     if activation_output.lower() == 'sigmoid':

AttributeError: 'function' object has no attribute 'shape'

Why is this happening? Y is clearly a numpy array.

I am calling a function model() which I have defined which takes in the input data set, the corresponding output labels, and a few hyperparameters and trains the model. This is the function definition for the model() function -

def model (X, Y, architecture, activation_functions, learning_rate = 0.001, print_cost = True, number_of_iterations = 10000):
    """
    Takes in the training set X, the labels Y, and all the required parameters and trains the defined model for the given number of iterations.
    Prints the cost if print_cost is true.
    """
    costs = []
    number_of_layers = len(architecture) - 1

    parameters = initialize_parameters(architecture)

    for i in range(number_of_iterations):

        prediction, cache = forward_propagation(X, parameters, number_of_layers, activation_functions)
        cost = calculate_cost(Y, prediction, activation_functions[-1])

        costs.append(cost)
        gradients = backward_propagation(X, Y, cache, number_of_layers)

        parameters = update_parameters(parameters, number_of_layers, gradients, alpha=0.01)

        if print_cost and i%100 == 0:
            print(f'Completed {i} iterarions.\n')
            print(f'Cost after iteration {i} = {cost}')

    plt.plot(costs)
    plt.xlabel('Iterations (in hundereds)')
    plt.ylabel('Cost')
    plt.title(f'Learning rate = {learning_rate}')
    plt.show()

    print(f'Ran {number_of_iterations} iterations. Returning parameters now.')
    print(f'The final cost of the model was: {costs[-1]}')
    print(f'The training accuracy was: {calculate_accuracy(X, Y, parameters, number_of_layers, activation_functions)}')

    return parameters

I am calling the function like this -

X_train = pd.read_csv('training_set.csv', header = None).to_numpy()
Y_train = pd.read_csv('training_labels.csv', header = None).to_numpy

model(X_train, Y_train, [10,5,5,1], ['relu','relu','relu','relu','sigmoid'])

The second parameter Y_train gets passed to the calculate_cost() function. And Y_train is clearly an array:/

🌐
PyTorch Forums
discuss.pytorch.org › t › attributeerror-list-object-has-no-attribute-shape › 124100
AttributeError: 'list' object has no attribute 'shape' - PyTorch Forums
June 14, 2021 - i’m trying to extract features and got this error from this line feats = model(samples).copy() features = torch.zeros(len(data_loader.dataset), feats.shape[-1]) i read that i should convert it to numpy but couldn’t write it well the first error was AttributeError: ‘list’ object has no attribute ‘clone’ so i changed it to copy but got current error in the title of the post
🌐
Itsourcecode
itsourcecode.com › home › attributeerror: list object has no attribute shape [solved]
Attributeerror: list object has no attribute shape [SOLVED]
March 24, 2023 - Therefore, this error usually occurs ... ‘list’ object has no attribute ‘shape'” occurs because the attribute “shape” is not defined for a list object in Python....
🌐
GitHub
github.com › python-pillow › Pillow › issues › 3106
Supporting 'shape' attribute for PIL.Image.Image? · Issue #3106 · python-pillow/Pillow
April 19, 2018 - a = np.ones((100, 120, 3)) b = Image.fromarray(a.astype(np.uint8)) b.shape ... --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-20-a8244287b6af> in <module>() ----> 1 b.shape AttributeError: 'Image' object has no attribute 'shape'
Author   shiba24
🌐
Researchdatapod
researchdatapod.com › home › how to solve python attributeerror: ‘list’ object has no attribute ‘shape’
How to Solve Python AttributeError: ‘list’ object has no attribute ‘shape’ - The Research Scientist Pod
February 23, 2022 - AttributeError occurs in a Python program when we try to access an attribute (method or property) that does not exist for a particular object. The part “‘list’ object has no attribute ‘shape’” tells us that the list object we are ...
🌐
GitHub
github.com › ultralytics › ultralytics › issues › 7019
[Dataset] AttributeError: 'NoneType' object has no attribute 'shape' · Issue #7019 · ultralytics/ultralytics
December 16, 2023 - File "/home/ubuntu/lnthach/env/lib/python3.8/site-packages/ultralytics/yolo/data/dataset.py", line 211, in getitem sample = self.torch_transforms(im) File "/home/ubuntu/lnthach/env/lib/python3.8/site-packages/torchvision/transforms/transforms.py", line 95, in call img = t(img) File "/home/ubuntu/lnthach/env/lib/python3.8/site-packages/ultralytics/yolo/data/augment.py", line 760, in call imh, imw = im.shape[:2] AttributeError: 'NoneType' object has no attribute 'shape'
Author   lengocthach
🌐
GitHub
github.com › ultralytics › ultralytics › issues › 9145
AttributeError: 'Image' object has no attribute 'shape'. · Issue #9145 · ultralytics/ultralytics
March 20, 2024 - Search before asking I have searched the YOLOv8 issues and found no similar bug report. YOLOv8 Component No response Bug @glenn-jocher I'm using two models at the same time first one is of clas...
Author   janardan-ds
🌐
GitHub
github.com › ultralytics › ultralytics › issues › 9399
raise AttributeError(name) AttributeError: shape · Issue #9399 · ultralytics/ultralytics
March 29, 2024 - raise AttributeError(name) AttributeError: shape#9399 · Copy link · Labels ·
Author   monkeycc
🌐
Fast.ai
forums.fast.ai › part 1 (2018)
AttributeError: 'NoneType' object has no attribute 'shape' - Part 1 (2018) - fast.ai Course Forums
December 22, 2017 - My data is organised as: train:- containing folder for each class valid :- containing folder for each class test:- contains all test images [error]