title: Getting classification probability for new audio files?
body: <p>I am using a CNN algorithm to make audio classification predictions on a new sample audio dataset. Recently, I changed the code to get the probability of each class (70% Guitar, 25% Violin, etc.)for each audio file but I am getting this error:</p>
  <pre><code>TypeError                                 Traceback (most recent call last)
  e:\Machine Learning\Pro_04_audio_class\predict_draft.py in 
       60                         help='threshold magnitude for np.int16 dtype')
       61     args, _ = parser.parse_known_args()
  ---&gt; 62     make_prediction(args)
       63 
  
  e:\Machine Learning\Pro_04_audio_class\predict_draft.py in make_prediction(args)
       39         X_batch = np.array(batch, dtype=np.float32)
       40         y_pred = model.predict(X_batch)
  ---&gt; 41         print('Predicted class: {}'.format(classes[y_pred]))
       42         results.append(y_pred)
       43     #np.save(os.path.join('logs', args.pred_fn), np.array(results))
  
  TypeError: only integer scalar arrays can be converted to a scalar index
  </code></pre>
  <p>I tried several different solutions but couldn't get past this. Is there any way that I can get class probabilities for new audio files?</p>
  <p>The code i am using:</p>
  <pre><code>
  def make_prediction(args):
  
  model = load_model(args.model_fn,
      custom_objects={'STFT':STFT,
                      'Magnitude':Magnitude,
                      'ApplyFilterbank':ApplyFilterbank,
                      'MagnitudeToDecibel':MagnitudeToDecibel})
  wav_paths = glob('{}/**'.format(args.src_dir), recursive=True)
  wav_paths = sorted([x.replace(os.sep, '/') for x in wav_paths if '.wav' in x])
  classes = sorted(os.listdir(args.class_src_dir))
  labels = [os.path.split(x)[0].split('/')[-1] for x in wav_paths]
  le = LabelEncoder()
  y_true = le.fit_transform(labels)
  results = []
  
  for z, wav_fn in tqdm(enumerate(wav_paths), total=len(wav_paths)):
      rate, wav = downsample_mono(wav_fn, args.sr)
      mask, env = envelope(wav, rate, threshold=args.threshold)
      clean_wav = wav[mask]
      step = int(args.sr*args.dt)
      batch = []
  
      for i in range(0, clean_wav.shape[0], step):
          sample = clean_wav[i:i+step]
          sample = sample.reshape(-1, 1)
          if sample.shape[0] &lt; step:
              tmp = np.zeros(shape=(step, 1), dtype=np.float32)
              tmp[:sample.shape[0],:] = sample.flatten().reshape(-1, 1)
              sample = tmp
          batch.append(sample)
      X_batch = np.array(batch, dtype=np.float32)
      y_pred = model.predict(X_batch)
      print('Predicted class: {}'.format(classes[y_pred]))
      results.append(y_pred)
  
  #np.save(os.path.join('logs', args.pred_fn), np.array(results))
  if name == 'main':
  
  parser = argparse.ArgumentParser(description='Audio Classification Training')
  parser.add_argument('--model_fn', type=str, default='models/conv2d.h5',
                      help='model file to make predictions')
  parser.add_argument('--pred_fn', type=str, default='y_pred',
                      help='fn to write predictions in logs dir')
  parser.add_argument('--src_dir', type=str, default='predict',
                      help='directory containing wavfiles to predict')
  parser.add_argument('--class_src_dir', type=str, default='clean',
                      help='directory containing wavfiles to predict')                   
  parser.add_argument('--dt', type=float, default=1.0,
                      help='time in seconds to sample audio')
  parser.add_argument('--sr', type=int, default=16000,
                      help='sample rate of clean audio')
  parser.add_argument('--threshold', type=str, default=20,
                      help='threshold magnitude for np.int16 dtype')
  args, _ = parser.parse_known_args()
  
  make_prediction(args)
  </code></pre>