<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Convolutions for Computer Vision
To build and test your intuition for convolutions, you will designa vertical line detector.
We'll apply that detector to each part of an image to create a new tensor showing where vertical lines are located.
The information in this tutorial will be useful in the ImageNet Challenges.
Step1:  Example Convolution
Step2:  Vertical Line Detector
Step3:  Now create a list that contains your convolutions, then apply them to the image data
Step4:  Let's see the image with just the horizontal and vertical line filters
Step5:  Building Models from Convolutions
This section describes how convolutions are combined in a way that enables computer vision.
At the end of this lesson, you will be able to write TensorFlow and Keras code to use one of the best models in computer vision.
Programming in TensorFlow and Keras
Choose the images to work with
Step6:  Write a function to read and prepare images for modeling
Step7:  Create a model with the pre-trained weights file and make predictions
Step8:  Visualization Time!
<ASSISTANT_TASK:>
Python Code:
import sys
from packages.learntools.deep_learning.exercise_1 import load_my_image, apply_conv_to_image, show, print_hints
Explanation: Convolutions for Computer Vision
To build and test your intuition for convolutions, you will designa vertical line detector.
We'll apply that detector to each part of an image to create a new tensor showing where vertical lines are located.
The information in this tutorial will be useful in the ImageNet Challenges.
End of explanation
# Detects light vs. dark pixels:
horizontal_line_conv = [[1, 1],
                        [-1, -1]]
Explanation: Example Convolution: Horizontal Line Detector
End of explanation
vertical_line_conv = [[-1, -1], 
                      [1, 1]]
Explanation: Vertical Line Detector
End of explanation
conv_list = [horizontal_line_conv, vertical_line_conv]
original_image = load_my_image()
print("Original Image: ")
show(original_image)
Explanation: Now create a list that contains your convolutions, then apply them to the image data:
End of explanation
for conv in conv_list:
    filtered_image = apply_conv_to_image(conv, original_image)
    show(filtered_image)
Explanation: Let's see the image with just the horizontal and vertical line filters:
End of explanation
from os.path import join
image_dir = 'data/dog_breed/train/'
img_paths = [join(image_dir, filename) for filename in
                    ['0246f44bb123ce3f91c939861eb97fb7.jpg',
                     '84728e78632c0910a69d33f82e62638c.jpg',
                     '8825e914555803f4c67b26593c9d5aff.jpg',
                     '91a5e8db15bccfb6cfa2df5e8b95ec03.jpg']]
Explanation: Building Models from Convolutions
This section describes how convolutions are combined in a way that enables computer vision.
At the end of this lesson, you will be able to write TensorFlow and Keras code to use one of the best models in computer vision.
Programming in TensorFlow and Keras
Choose the images to work with:
End of explanation
import numpy as np
import tensorflow as tf
from tensorflow.python.keras.applications.resnet50 import preprocess_input
from tensorflow.python.keras.preprocessing.image import load_img, img_to_array
image_size=224
def read_and_prep_images(img_paths, img_height=image_size, img_width=image_size):
    imgs = [load_img(img_path, target_size=(img_height, img_width)) for img_path in img_paths]
    img_array = np.array([img_to_array(img) for img in imgs])
    return preprocess_input(img_array)
Explanation: Write a function to read and prepare images for modeling:
End of explanation
from tensorflow.python.keras.applications import ResNet50
my_model = ResNet50(weights='inputs/resnet50_weights_tf_dim_ordering_tf_kernels.h5')
test_data = read_and_prep_images(img_paths)
preds = my_model.predict(test_data)
Explanation: Create a model with the pre-trained weights file and make predictions:
End of explanation
import sys
# Add a directory with prefabricated code to your path.
sys.path.append('inputs/utils')
from decode_predictions import decode_predictions
from IPython.display import Image, display
most_likely_labels = decode_predictions(preds, top=3, class_list_path='inputs/imagenet_class_index.json')
for i, img_path in enumerate(img_paths):
    display(Image(img_path))
    print(most_likely_labels[i])
Explanation: Visualization Time!
End of explanation
<END_TASK>