title: Keras Model giving TypeError: only size-1 arrays can be converted to Python scalars
body: <p>I'm training a model to produce image masks. This error keeps popping up, and I can not determine the cause. Help would be appreciated. </p>
  
  <p>Error statement:</p>
  
  <pre><code>File "--\Users\-----\Anaconda3\lib\site-packages\keras\initializers.py", line 209, in __call__
  scale /= max(1., float(fan_in + fan_out) / 2)
  TypeError: only size-1 arrays can be converted to Python scalars
  </code></pre>
  
  <p>Researching online, this error occurs when normal lists are used with numpy functions, but in my case, the arrays used are numpy arrays. Below, I've attached the code.</p>
  
  <pre><code>import cv2
  import glob
  import numpy as np
  from keras.models import Sequential
  from keras.layers import Dense, Dropout, Activation, Flatten
  from keras.layers import Convolution2D, MaxPooling2D
  from keras.utils import np_utils
  from keras.datasets import mnist
  from keras import backend as K
  K.set_image_dim_ordering('tf')
  np.random.seed(123)  # for reproducibility
  
  image_list = [] 
  test_list = []
  
  for filename in glob.glob("image/*.jpg*"): 
      im = cv2.imread(filename)
      im_r = cv2.resize(im,(200, 200), interpolation = cv2.INTER_AREA) 
      image_list.append(im_r)
  
  for filename in glob.glob("test/*.png*"): 
      im = cv2.imread(filename)
      im_r = cv2.resize(im,(200, 200), interpolation = cv2.INTER_AREA) 
      im_r = np.ravel(im_r)
      test_list.append(im_r)
  
  x_data = np.array(image_list)
  y_data = np.array(test_list)
  x_data = x_data.astype("float32")
  y_data = y_data.astype("float32")
  x_data /= 255
  y_data /= 255
  
  X_train = x_data
  Y_train = y_data
  
  model = Sequential()
  model.add(Convolution2D(32, 5, 5, activation='relu', input_shape=(200, 200, 3)))
  model.add(MaxPooling2D(pool_size=(2,2))) 
  model.add(Convolution2D(32, 5, 5, activation='relu'))
  model.add(MaxPooling2D(pool_size=(2,2))) 
  model.add(Convolution2D(32, 3, 3, activation='relu'))
  model.add(MaxPooling2D(pool_size=(2,2))) 
  model.add(Dropout(0.25))
  model.add(Flatten()) 
  model.add(Dense(128, activation='relu')) 
  model.add(Dropout(0.5)) 
  model.add(Dense(Y_train[0], activation='sigmoid'))
  print('hello')
  
  model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
  loss = acc = 0
  while acc &lt; 0.9999:
      model.fit(X_train, Y_train, batch_size=32, nb_epoch=10, verbose=1)
      loss, acc = model.evaluate(X_train, Y_train, verbose=1)
  model.save("model_state_no_mapping")
  </code></pre>