Skip to content

Commit

Permalink
Fix "invalid index of a 0-dim tensor. Use tensor.item() to convert a …
Browse files Browse the repository at this point in the history
…0-dim tensor to a Python number" error on line 193 and add some output to inform if GPU was detected.
  • Loading branch information
scottvr committed Jul 20, 2021
1 parent f1de11d commit 93965d4
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion NeuralStyleTransfer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 93965d4

Please sign in to comment.