Ejemplo n.º 1
0
def prob_image(args):
  list_predictions = list()
  pred = Prediction(args.proto_path,args.bin_path)
  max_value = 512 
  curr_value = 0


  with open(args.images,'r') as file_image:
    list_images = list()
    list_good_class = list()
    for line in file_image:
      splitted = line.split('\t')
      list_images.append(splitted[2].strip())
      curr_value = curr_value + 1
      if curr_value < max_value:
        continue
      else:
        #predict using value
        predictions = pred.predict_multi(list_images)
        list_images = list()
        list_good_class = list()
        curr_value = 0
        list_predictions.append(predictions)
        print predictions.shape
        
    if len(list_images) > 0:
      #predict using value
      predictions = pred.predict_multi(list_images)
      list_predictions.append(predictions)
  
  all_pred = np.vstack(list_predictions)
  np.save('fine_sand.npy',all_pred)
  np.savetxt('probabilities_kaggle_aug_fine_m.txt', all_pred, fmt='%1.9e')
Ejemplo n.º 2
0
def test_accuracy_multi(args):
  # Compute Accuracy of images from input file
  # Code predict many images at one time. The value is set by max_value
  # Same value should be set in proto file
  # It is done because of speed reason
  
  pred = Prediction(args.proto_path,args.bin_path)
  max_value = 512 
  curr_value = 0
  list_all_result = list()
  list_good_class_all = list()
    
  with open(args.images,'r') as file_image:
    list_images = list()
    list_good_class = list()
    for line in file_image:
      splitted = line.split(' ')
      #if not os.path.isfile(splitted[0].strip()):
        #continue
      list_good_class.append(int(splitted[1]))
      list_images.append(splitted[0].strip())
      curr_value = curr_value + 1
      if curr_value < max_value:
        continue
      else:
        #predict using value
        predictions = pred.predict_multi(list_images)
        list_all_result.append(predictions)
        list_good_class_all.extend(list_good_class)
        list_good_class = list()
        list_images = list()
        curr_value = 0
        
    #predict last package of data, which is smaller than max_value
    if len(list_images) > 0:
      predictions = pred.predict_multi(list_images)
      list_all_result.append(predictions)
          
  #test loss
  list_good_class_all.extend(list_good_class)
  y_truth = np.asarray(list_good_class_all)
  y_pred = np.vstack(list_all_result)
  y_pred_label = np.argmax(y_pred, axis=1)
  print y_truth.shape, y_pred.shape
  print "Accuracy: ", accuracy_score(y_truth,y_pred_label)
  print "Loss: ",multiclass_log_loss(y_truth,y_pred)
  plot_confusion_matrix(y_truth,y_pred_label)
  np.save('casia_deep.npy',y_pred)