I have the following code which uses TensorFlow. After I reshape a list, it says
'list' object has no attribute 'shape'
when I try to print its shape.
image_batch, label_batch = next(iter(train_ds))
feature_batch = train_model(image_batch)
print(feature_batch.shape)
my code for yolov3 model
# define the model
model = make_yolov3_model()
# load the model weights
# I have loaded the pretrained weights in a separate dataset
weight_reader = WeightReader('yolov3.weights')
# set the model weights into the model
weight_reader.load_weights(model)
# save the model to file
model.save('model.h5')
# load yolov3 model
from keras.models import load_model
train_model = load_model('model.h5', compile=False)
Output
AttributeError Traceback (most recent call last) ~\AppData\Local\Temp\ipykernel_4412\2773113981.py in <module> 1 image_batch, label_batch = next(iter(train_ds)) 2 feature_batch = train_model(image_batch) ----> 3 print(feature_batch.shape)
AttributeError: 'list' object has no attribute 'shape'
Could anyone please tell me what I am missing?
CodePudding user response:
The Python "AttributeError: 'list' object has no attribute 'shape'"
occurs when we try to access the shape attribute on a list.
Lists do not have any attribute name shape.
To solve this error, pass the list to the numpy.array()
method to create a numpy array before accessing the shape attribute.
So, you can do:
import numpy as np
feature_batch=np.array(feature_batch)
print(feature_batch.shape)
CodePudding user response:
I tried then showing another error
could not broadcast input array from shape (16,7,7,255) into shape (16,)