小编Cof*_*Guy的帖子

如何将函数作为变量运行?

我有一个名为“LoadDataClassForImageClassification”的函数,我不希望用户一次又一次地输入它......我试过了

def LoadDataClassForImageClassification():
    print('Loading...')
    ## ML THINGS
x = LoadDataClassForImageClassification()
x()
Run Code Online (Sandbox Code Playgroud)

python variables function python-2.7 python-3.x

3
推荐指数
1
解决办法
49
查看次数

如何将 torch.device('cuda' if torch.cuda.is_available() else 'cpu') 编写为完整的 if else 语句?

我是 Pytorch 的初学者,想将这个语句作为一个整体输入 if else 语句:-

torch.device('cuda' if torch.cuda.is_available() else 'cpu')
Run Code Online (Sandbox Code Playgroud)

有人可以帮助我吗?

python gpu if-statement pytorch

2
推荐指数
1
解决办法
5904
查看次数