Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

ValueError: setting an array element with a sequence.

I took a bunch of images converted them into gray then stored them into img_data_list then i converted them to a numpy array everything works fine untill now here's part of code that works

import cv2
import os
import numpy as np

people = ['s1', 's2']
num_classes = 2
img_data_list = []
labels = []
valid_images = [".jpg",".gif",".png"]

for index, person in enumerate(people):
  print(index)
  dir_path = 'I:\\project_face_detection\\face_detetion\\training_data\\' + person
  for img_path in os.listdir(dir_path):
    name, ext = os.path.splitext(img_path)
    if ext.lower() not in valid_images:
        continue

    img_data = cv2.imread(dir_path + '\\' + img_path)
    # convert image to gray
    img_data=cv2.cvtColor(img_data, cv2.COLOR_BGR2GRAY)
    img_data_list.append(img_data)
    labels.append(index)


img_data = np.array(img_data_list)

but when I try to convert the array into float32 data type I get the ValueError

img_data = img_data.astype('float32')

here's the error

 ValueError: setting an array element with a sequence.

here's how my images are stored

- training_data
   - s1
       - 0.jpg
       - 1.jpg
   - s2
      - 0.jpg
      - ......

If you guys can help me out in any way I'd be grateful thanks for looking into it :) .