简体   繁体   中英

How do i reshape my dataset to train a CNN

Hello i have a dataset of 32FC1 Images of 80x60 and what im doing is to reshape the dataset to transform it and label it so it could be used to train a CNN but when i reshape my dataset i get the following error:

arraynegativos= ds_negatives.reshape(( n_negatives_img, img_width, img_height))
arraypositivos= ds_positives.reshape((n_positives_img, img_width, img_height))

AttributeError: 'list' object has no attribute 'reshape'

So i converted my ds_negative to numpy array like this:

ds_negatives1 = np.array(ds_negatives)

But it gives me this error:

cannot reshape array of size 1 into shape (26308,80,60)

So now im a bit confused, how do i transform my dataset to be reshaped into that?

Here is the link of the script so u can see it better.

https://colab.research.google.com/drive/1KzoHXA8Y6lcyvq7K7segFfJp2AIw9P45?usp=sharing

When you say ds_negatives = ["/content/drive/MyDrive/Colab Notebooks/negative_depth.txt"] you are not setting ds_negatives to the content of that file but simply to a string containing the file path. Therefore the list (and np array you create from it) only contain one item. Depending on how you want to read the text file you should use something like open("path", "r").read() or .readlines()

You need to load the images into a list or array. Try using "imread" and "append" functions like in the following script:

imagesWithLabels = []
for filename in listdir('C:/AI/images/cats'):
    # load image
    img_data =   image.imread('C:/AI/images/cats/' +\
    filename)
    # store loaded image in a list
    imagesWithLabels.append((img_data,0))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM