Week 3 programming c2

The tests is passed but i am getting the following error

how to correct this ?

Your compute_loss function has a defect.

import time
from collections import deque, namedtuple

import gym
import numpy as np
import PIL.Image
import tensorflow as tf
import utils
experience = namedtuple(“Experience”, field_names=[“state”, “action”, “reward”, “next_state”, “done”])
from pyvirtualdisplay import Display
from tensorflow.keras import Sequential
from tensorflow.keras.layers import Dense, Input
from tensorflow.keras.losses import MSE
from tensorflow.keras.optimizers import Adam
num_episodes=2000
temp=-1
q_network = Sequential([
Input(shape=state_size),
Dense(units=64, activation=‘relu’),
Dense(units=64, activation=‘relu’),
Dense(units=num_actions, activation=‘linear’),
])

Create the target Q^-Network

target_q_network = Sequential([
Input(shape=state_size),
Dense(units=64, activation=‘relu’),
Dense(units=64, activation=‘relu’),
Dense(units=num_actions, activation=‘linear’),
])

def compute_loss(experiences, gamma, q_network, target_q_network):
global temp
# Unpack the mini-batch of experience tuples
states, actions, rewards, next_states, done_vals = experiences

# Compute max Q^(s,a)
max_qsa = tf.reduce_max(target_q_network(next_states), axis=-1)

# Set y = R if episode terminates, otherwise set y = R + γ max Q^(s,a).
if temp == num_episodes :
    y_targets = rewards
else:
    y_targets = rewards + (gamma * max_qsa *(1 - done_vals))
    temp=temp+1

# Get the q_values
q_values = q_network(states)
q_values = tf.gather_nd(q_values, tf.stack([tf.range(q_values.shape[0]),
                                            tf.cast(actions, tf.int32)], axis=1))

# Calculate the loss
loss = MSE(y_targets, q_values)
return loss

can someone tell me where is my mistake

Please don’t post your code on the forum.

Sorry, i cannot review your code at this time.