import IPython
import time
import pickle
import librosa
import librosa.display
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
from torch.utils.data import Dataset, DataLoader
from torchvision.models import resnet34

def spec_to_image(spec, eps=1e-6):
    mean = spec.mean()
    std = spec.std()
    spec_norm = (spec - mean) / (std + eps)
    spec_min, spec_max = spec_norm.min(), spec_norm.max()
    spec_scaled = 255 * (spec_norm - spec_min) / (spec_max - spec_min)
    spec_scaled = spec_scaled.astype(np.uint8)
    return spec_scaled

def get_melspectrogram_db(file_path, sr=None, n_fft=2048, hop_length=512, n_mels=128, fmin=20, fmax=8300, top_db=80):
  wav,sr = librosa.load(file_path,sr=sr)
  if wav.shape[0]<5*sr:
    wav=np.pad(wav,int(np.ceil((5*sr-wav.shape[0])/2)),mode='reflect')
  else:
    wav=wav[:5*sr]
  spec=librosa.feature.melspectrogram(wav, sr=sr, n_fft=n_fft,
              hop_length=hop_length,n_mels=n_mels,fmin=fmin,fmax=fmax)
  spec_db=librosa.power_to_db(spec,top_db=top_db)
  return spec_db

t1 = time.time()

device=torch.device('cuda:0')

with open('D:/Python36/ESC-50-master/indtocat.pkl','rb') as f:
  indtocat = pickle.load(f)

resnet_model = torch.load("D:/Python36/ESC-50-master/esc50resnet.pth")

filename='D:/Python36/Sound_datatest/Dry_cough.wav'
spec=spec_to_image(get_melspectrogram_db(filename))
spec_t=torch.tensor(spec).to(device, dtype=torch.float32)
pr=resnet_model.forward(spec_t.reshape(1,1,*spec_t.shape))
ind = pr.argmax(dim=1).cpu().detach().numpy().ravel()[0]
t2=time.time()
print("{}s".format(t2-t1))
print(indtocat[ind])
IPython.display.display(IPython.display.Audio(filename=filename))

Hi sir @ptrblck  actually now I get this type of error
Traceback (most recent call last):
  File "d:/Python36/pickle_test.py", line 49, in <module>
    resnet_model = torch.load("D:/Python36/ESC-50-master/esc50resnet.pth")
  File "D:\Python36\lib\site-packages\torch\serialization.py", line 526, in load
    if _is_zipfile(opened_file):
  File "D:\Python36\lib\site-packages\torch\serialization.py", line 76, in _is_zipfile
    if ord(magic_byte) != ord(read_byte):
TypeError: ord() expected a character, but string of length 0 found

Can you please tell what this means?
How do I load my previously trained model correctly?