五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

李沐python教程 運(yùn)行中g(shù)rad can be implicitly created only for scalar out

2023-07-30 16:47 作者:Tery老楊  | 我要投稿

d2l包中封裝的函數(shù)有問(wèn)題,和前面課程里實(shí)現(xiàn)的有點(diǎn)不一樣所以會(huì)出問(wèn)題。把這個(gè)文件C:\Users\86156\miniconda3\envs\d2l\Lib\site-packages\d2l\torch.py 中的243行的函數(shù)改成:

# Defined in file: ./chapter_linear-networks/softmax-regression-scratch.md

def train_epoch_ch3(net, train_iter, loss, updater):

? ? """The training loop defined in Chapter 3."""

? ? # Set the model to training mode

? ? if isinstance(net, torch.nn.Module):

? ? ? ? net.train()

? ? # Sum of training loss, sum of training accuracy, no. of examples

? ? metric = Accumulator(3)

? ? for X, y in train_iter:

? ? ? ? # Compute gradients and update parameters

? ? ? ? y_hat = net(X)

? ? ? ? l = loss(y_hat, y)

? ? ? ? if isinstance(updater, torch.optim.Optimizer):

? ? ? ? ? ? # Using PyTorch in-built optimizer & loss criterion

? ? ? ? ? ? updater.zero_grad()

? ? ? ? ? ? l.mean().backward()

? ? ? ? ? ? updater.step()

? ? ? ? ? ? #metric.add(float(l) * len(y), accuracy(y_hat, y),

? ? ? ? ? ? # ? ? ? ? ? y.size().numel())

? ? ? ? else:

? ? ? ? ? ? # Using custom built optimizer & loss criterion

? ? ? ? ? ? l.sum().backward()

? ? ? ? ? ? updater(X.shape[0])

? ? ? ? metric.add(float(l.sum()), accuracy(y_hat, y), y.numel())

? ? # Return training loss and training accuracy

? ? return metric[0] / metric[2], metric[1] / metric[2]



李沐python教程 運(yùn)行中g(shù)rad can be implicitly created only for scalar out的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
临武县| 湘潭县| 锦州市| 来宾市| 东明县| 云南省| 柳林县| 昌乐县| 阿尔山市| 库伦旗| 深州市| 博乐市| 佛坪县| 阜平县| 吉隆县| 象州县| 吉水县| 大同县| 延川县| 南丹县| 通州市| 江华| 榕江县| 弋阳县| 无极县| 天峨县| 泸西县| 闵行区| 吉隆县| 固镇县| 仲巴县| 景泰县| 柘荣县| 长武县| 玉环县| 雅江县| 临汾市| 巩留县| 阿城市| 麻城市| 自贡市|