'There is no error in the dataset of DS1 images, but I am getting errors in 250 and 1000

flags.DEFINE_boolean(
    'dpsgd', False, 'If True, train with DP-SGD . If False, '
    'train with vanilla SGD.')
flags.DEFINE_float('learning_rate', 0.15, 'Learning rate for training')
flags.DEFINE_float('noise_multiplier', 0.1,
                   'Ratio of the standard deviation to the clipping norm')
flags.DEFINE_float('l2_norm_clip', 1.0, 'Clipping norm')
flags.DEFINE_integer('batch_size', 8, 'Batch size')
flags.DEFINE_integer('epochs', 50, 'Number of epochs')
flags.DEFINE_integer(
    'microbatches', 8, 'Number of microbatches '
    '(must evenly divide batch_size)')
flags.DEFINE_string('model_dir', None, 'Model directory')

FLAGS = flags.FLAGS

def load_mnist():
  """Loads MNIST and preprocesses to combine training and validation data."""
  
  MAX_SIZE = (200, 200) 
  image_no = 1

  images = glob.glob("D:\\Enformatik\\Covid-19\\Program\\Uygulama\\verisetleri\\dataset2\\normal\\*.png")
  for image in images:
        with open(image, 'rb') as file:
            img = Image.open(file)
            width, height = img.size
            img.thumbnail(MAX_SIZE,Image.ANTIALIAS)
            name = "D:\\Enformatik\\Covid-19\\Program\\Uygulama\\verisetleri\\dataset2\\normal\\normal\\file_" + str(image_no) + ".png"
            image_no += 1
            img.save(name,"PNG")
    
    
  image_no = 1
    
  images = glob.glob("D:\\Enformatik\\Covid-19\\Program\\Uygulama\\verisetleri\\dataset2\\covid\\*.png")
  for image in images:
        with open(image, 'rb') as file:
            img = Image.open(file)
            width, height = img.size
            img.thumbnail(MAX_SIZE,Image.ANTIALIAS)
            name = "D:\\Enformatik\\Covid-19\\Program\\Uygulama\\verisetleri\\dataset2\\covid\\covid\\file_" + str(image_no) + ".png"
            image_no += 1
            img.save(name,"PNG")
  
  negatif = [cv2.imread(file, 0) for file in glob.glob("D:\\Enformatik\\Covid-19\\Program\\Uygulama\\verisetleri\\dataset2\\normal\\normal\\*.png")]
  pozitif = [cv2.imread(file, 0) for file in glob.glob("D:\\Enformatik\\Covid-19\\Program\\Uygulama\\verisetleri\\dataset2\\covid\\covid\\*.png")]

  negatif_label=[0]*160
  pozitif_label=[1]*90

  full_image=np.asarray(negatif+pozitif)
  full_label=np.asarray(negatif_label+pozitif_label)

  x_train, x_test, y_train, y_test = train_test_split(full_image, full_label, test_size=0.20, random_state=42)
  #
  
  x_train = x_train.astype('float32')
  x_test = x_test.astype('float32')
  x_train /= 255
  x_test /= 255
  
  train_data, train_labels = x_train, y_train
  test_data, test_labels = x_test, y_test

  train_data = train_data.reshape((train_data.shape[0], 200, 200, 1))
  test_data = test_data.reshape((test_data.shape[0], 200, 200, 1))

When I give the ads code 500, it does not give an error. but when I want to use version 250,1000 it gives the following error. I wonder why? I would be glad if you help.

error:

  File "C:\Users\PC\Desktop\trans\sigmoidrelu250.py", line 123, in load_mnist
    x_train = x_train.astype('float32')
ValueError: setting an array element with a sequence.


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source