From 93965d42cd85f1032ae67054a1b5604fac87aa02 Mon Sep 17 00:00:00 2001 From: ScottVR Date: Mon, 19 Jul 2021 21:34:34 -0500 Subject: [PATCH] Fix "invalid index of a 0-dim tensor. Use tensor.item() to convert a 0-dim tensor to a Python number" error on line 193 and add some output to inform if GPU was detected. --- NeuralStyleTransfer.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/NeuralStyleTransfer.py b/NeuralStyleTransfer.py index 9e481e9..2c2141d 100644 --- a/NeuralStyleTransfer.py +++ b/NeuralStyleTransfer.py @@ -95,9 +95,11 @@ def read_audio_spectum(filename): if torch.cuda.is_available(): style_float = Variable((torch.from_numpy(style_audio)).cuda()) content_float = Variable((torch.from_numpy(content_audio)).cuda()) + print('using CUDA') else: style_float = Variable(torch.from_numpy(style_audio)) content_float = Variable(torch.from_numpy(content_audio)) + print('using CPU') #style_float = style_float.unsqueeze(0) #style_float = style_float.view([1025,1,2500]) @@ -190,7 +192,7 @@ def closure(): run[0] += 1 if run[0] % 100 == 0: print("run {}:".format(run)) - print('Style Loss : {:8f}'.format(style_score.data[0])) #CHANGE 4->8 + print('Style Loss : {:8f}'.format(style_score.item())) #CHANGE 4->8 print() return style_score