国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(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ó)家法律
武山县| 连城县| 富平县| 西平县| 大方县| 论坛| 巴彦县| 出国| 株洲市| 化德县| 麻栗坡县| 开封市| 翼城县| 个旧市| 武陟县| 黔西| 兰溪市| 竹山县| 宁蒗| 徐水县| 怀集县| 东丽区| 梁山县| 景泰县| 莫力| 蛟河市| 黄石市| 洛川县| 延寿县| 淮安市| 舟山市| 凤山县| 瓦房店市| 榆社县| 平原县| 岫岩| 安泽县| 鄂尔多斯市| 海丰县| 长丰县| 白银市|