释义:
该句代码的意思是指定 和参数相同的设备。
具体解释:
首先,需要理解 next() 函数
它用于返回迭代器的下一个项目
在这里的
device = next(self.parameters()).device
next(self.parameters()) 用于返回第一个参数
整句代码就是指定 使用和参数相同的设备
参考示例:
def parse_data_batch(self, batch):
"""Parse data batch to form inputs and targets for model training/evaluating
"""
# use same device as parameters
device = next(self.parameters()).device
print(next(self.parameters()))
print(next(self.parameters()).device)
text, text_length, mel, stop, mel_length = batch
text = text.to(device).long()
text_length = text_length.to(device).long()
mel = mel.to(device).float()
stop = stop.to(device).float()
return (text, text_length, mel), (mel, stop)