title: expected inputs to have 4 dimensions, but got array with shape (32, 549, 1)
body: <p>Im trying to test a trained model of cnn with keras, but when I run the code, ' have the error: </p>
  
  <blockquote>
    <p>expected inputs to have 4 dimensions, but got array with shape (32,
    549, 1). </p>
  </blockquote>
  
  <p>That (32,549,1) is the size of my log-spectogram that I used to train and test my cnn whit good results. Except for the last error. </p>
  
  <p>I tried with np.rezise(-1, amp) and y=(-1, amp) to try to increase my vector but it doesn't work, I really don't know what to do.</p>
  
  <pre><code>DIR = 'C:/Users/ROBERTO VILCHEZ/Desktop/Redes/TRAIN/ayuda/ayuda_1.wav'
  SAMPLE_RATE = 88200
  model=load_model('C:/Users/ROBERTO VILCHEZ/Desktop/Redes/mi_modelo.h5')
  
  def read_wav_file(x):
     _, wav = wavfile.read(x) 
     # Normalize
     wav = wav.astype(np.float32) / np.iinfo(np.int16).max
     return wav
  
  def log_spectrogram(wav):
      freqs, times, spec = stft(wav, SAMPLE_RATE, nperseg = 400, noverlap = 240, nfft = 512, padded = False, boundary = None)
      # Log spectrogram
      amp = np.log(np.abs(spec)+1e-10)
  
      return freqs, times, amp
  
  
  threshold_freq=5500
  
  eps=1e-10
  
  x=DIR 
  
  wav = read_wav_file(x)
  
  L = 88200
  
  if len(wav) &gt; L:
      i = np.random.randint(0, len(wav) - L)
      wav = wav[i:(i+L)]  
  
  elif len(wav) &lt; L:
      rem_len = L - len(wav)
      silence_part = np.random.randint(-100,100,88200).astype(np.float32) / 
  
  np.iinfo(np.int16).max
  j = np.random.randint(0, rem_len)
  silence_part_left  = silence_part[0:j]
  silence_part_right = silence_part[j:rem_len]
  wav = np.concatenate([silence_part_left, wav, silence_part_right])
  freqs, times, spec = stft(wav, L, nperseg = 400, noverlap = 240, nfft = 
  512, padded = False, boundary = None)
  
  if threshold_freq is not None:
      spec = spec[freqs &lt;= threshold_freq,:]
      freqs = freqs[freqs &lt;= threshold_freq]
  
      amp = np.log(np.abs(spec)+eps)
  
      y = np.expand_dims(amp, axis=3)
  
      res = model.predict(y)
  </code></pre>
  
  <p>All the rest of the code works OK, but only that last part show me that error expected inputs to have 4 dimensions, but got array with shape (32, 549, 1).</p>
  
  <p>FULL ERROR:</p>
  
  <blockquote>
  <pre><code>Traceback (most recent call last):
      File "C:\Users\ROBERTO
  VILCHEZ\Desktop\Redes\prueba.py", line 76, in &lt;module&gt;
      res = model.predict(y)    File "C:\Users\ROBERTO VILCHEZ\AppData\Roaming\Python\Python36\site-packages\keras\engine\training.py",
  line 1149, in predict
      x, _, _ = self._standardize_user_data(x)   File "C:\Users\ROBERTO VILCHEZ\AppData\Roaming\Python\Python36\site-packages\keras\engine\training.py",
  line 751, in _standardize_user_data
      exception_prefix='input')    File "C:\Users\ROBERTO VILCHEZ\AppData\Roaming\Python\Python36\site-packages\keras\engine\training_utils.py", line 128, in standardize_input_data
      'with shape ' + str(data_shape))
  </code></pre>
  </blockquote>
  
  <p>ValueError: Error when checking input: expected inputs to have 4
  dimensions, but got array with shape (32, 549, 1)</p>