title: Remove directory from filepath
body: <p>I've made a convolutional neural network using Python and Keras. I am testing my models on test sets with random number of images per class (1 folder containing x amount of images). I am able to get a data frame with the showing the file name for the image and the directory, and the prediction. I would like to remove the directory from the file name.  It shows random 350 images/dogs1.tif and I want it to just say dogs1.tif.</p>
  <pre><code>  #import my model
  new_model = tf.keras.models.load_model('model folder')
  #upload my test data
  train_datagen = ImageDataGenerator(rescale=1./255)
  
  test_batches = train_datagen.flow_from_directory(
          'folder containing random images',
          target_size=(224, 224),
          batch_size=10,
          classes = None,
          class_mode = None,
          shuffle = False)
  
  #my prediction
  predictions = new_model.predict(test_batches, steps=35, verbose=0)
  
  #rounding my predctions
  rounded_predictions = np.argmax(predictions, axis = -1)
  
  #converting one hot encoded labels to categorical labels 
  labels =[&quot;dog&quot;,&quot;cat&quot;,&quot;horse&quot;]
  names = [0,1,2]
  labels_name = dict(zip(names, labels))
  
  #joining them together
  labels_name = dict((v,k) for k,v in labels_name.items())
  predictions = [labels[k] for k in rounded_predictions]
  
  #getting files names for the images
  filenames= test_batches.filenames
  
  #creating the dataframe
  results=pd.DataFrame({&quot;file&quot;:filenames,&quot;pr&quot;:predictions})
  </code></pre>