Your idea of passing the input data to the model, getting the output, and using argmax to get the predictions, is correct.
However, the forward pass (passing the data to the model) as well as the prediction calculation are not used in your code, so predicted is undefined and raises the error.