Building a DQN model in PyTorch
We discussed the theory behind DQNs in the previous section. In this section, we will take a hands-on approach. Using PyTorch, we will build a CNN-based DQN model that will train an agent to play the video game known as Pong. The goal of this exercise is to demonstrate how to develop DRL applications using PyTorch. Let's get straight into the exercise.
Initializing the main and target CNN models
In this exercise, we will only show the important parts of the code for demonstration purposes. In order to access the full code, visit https://github.com/PacktPublishing/Mastering-PyTorch/blob/master/Chapter09/pong.ipynb. Follow these steps:
- First, we need to import the necessary libraries:
# general imports import cv2 import math import numpy as np import random # reinforcement learning related imports import re import atari_py as ap from collections import deque from gym import make, ObservationWrapper, Wrapper from gym.spaces import Box...