text: from pathlib import Path
  import numpy as np
  import joblib
  from keras.preprocessing import image
  from keras.applications import vgg16
  from keras.models import Sequential
  from keras.layers import Dense, Dropout, Flatten
  
  
  # Path to folders with training data
  dog_path = Path("img") / "dogs"
  not_dog_path = Path("img") / "not_dogs"
  
  images = []
  labels = []
  
  # Load all the not-dog images
  for img in not_dog_path.glob("*.png"):
      # Load the image from disk
      img = image.load_img(img)
  
      # Convert the image to a numpy array
      image_array = image.img_to_array(img)
  
      # Add the image to the list of images
      images.append(image_array)
  
      # For each 'not dog' image, the expected value should be 0
      labels.append(0)
  
  # Load all the dog images
  for img in dog_path.glob("*.png"):
      # Load the image from disk
      img = image.load_img(img)
  
      # Convert the image to a numpy array
      image_array = image.img_to_array(img)
  
      # Add the image to the list of images
      images.append(image_array)
  
      # For each 'dog' image, the expected value should be 1
      labels.append(1)
  
  # Create a single numpy array with all the images we loaded
  x_train = np.array(images)
  
  # Also convert the labels to a numpy array
  y_train = np.array(labels)
  
  # Normalize image data to 0-to-1 range
  x_train = vgg16.preprocess_input(x_train)
  
  # Load a pre-trained neural network to use as a feature extractor
  feature_extraction_model = vgg16.VGG16(weights='imagenet', include_top=False, input_shape=(64, 64, 3))
  
  # Extract features for each image (all in one pass)
  features_x = feature_extraction_model.predict(x_train)
  
  # Create a model and add layers
  model = Sequential()
  
  model.add(Flatten(input_shape=features_x.shape[1:]))
  model.add(Dense(256, activation='relu'))
  model.add(Dropout(0.5))
  model.add(Dense(1, activation='sigmoid'))
  
  # Compile the model
  model.compile(
      loss="binary_crossentropy",
      optimizer="adam",
      metrics=['accuracy']
  )
  
  # Train the model
  model.fit(
      features_x,
      y_train,
      epochs=10,
      shuffle=True
  )
  
  # Load an image file to test, resizing it to 64x64 pixels (as required by this model)
  img = image.load_img("img/not_dog.png", target_size=(64, 64))
  # img = image.load_img("img/dog.png", target_size=(64, 64))
  
  # Convert the image to a numpy array
  image_array = image.img_to_array(img)
  
  # Add a forth dimension to the image (since Keras expects a bunch of images, not a single image)
  images = np.expand_dims(image_array, axis=0)
  
  # Normalize the data
  images = vgg16.preprocess_input(images)
  
  # Use the pre-trained neural network to extract features from our test image (the same way we did to train the model)
  features = feature_extraction_model.predict(images)
  
  # Given the extracted features, make a final prediction using our own model
  results = model.predict(features)
  
  # Since we are only testing one image with possible class, we only need to check the first result's first element
  single_result = results[0][0]
  
  # Print the result
  print("Likelihood that this image contains a dog: {}%".format(int(single_result * 100)))