jaimetang / book-code Goto Github PK
View Code? Open in Web Editor NEW《深度学习之PyTorch实战计算机视觉》全书代码
《深度学习之PyTorch实战计算机视觉》全书代码
Training...
Batch 500,Model1 Train Loss:0.0951,Model1 Train ACC:96.0000,Model2 Train Loss:0.5438,Model2 Train ACC:82.0000, Blending_Model ACC:96.0000
Batch 1000,Model1 Train Loss:0.0716,Model1 Train ACC:97.0000,Model2 Train Loss:0.4565,Model2 Train ACC:88.0000, Blending_Model ACC:97.0000
Epoch, Model1 Loss:0.0713, Model1 Acc:97.0000%, Model2 Loss:0.4449, Model2 Acc:88.0000%,Blending_Model ACC:97.0000
Validing...
Epoch, Model1 Loss:0.0491, Model1 Acc:98.0000%, Model2 Loss:0.2798, Model2 Acc:96.0000%,Blending_Model ACC:98.0000
Epoch 1/4
Training...
Batch 500,Model1 Train Loss:35.3260,Model1 Train ACC:96.0000,Model2 Train Loss:0.2745,Model2 Train ACC:95.0000, Blending_Model ACC:96.0000
Batch 1000,Model1 Train Loss:nan,Model1 Train ACC:73.0000,Model2 Train Loss:0.2537,Model2 Train ACC:95.0000, Blending_Model ACC:73.0000
Epoch, Model1 Loss:nan, Model1 Acc:71.0000%, Model2 Loss:0.2503, Model2 Acc:95.0000%,Blending_Model ACC:71.0000
Validing...
tensor.sub_(mean[:, None, None]).div_(std[:, None, None])
RuntimeError: output with shape [1, 28, 28] doesn't match the broadcast shape [3, 28, 28]
以上是报错,似乎是mnist数据集是灰度图?然后代码中处理时将均值设置的是对rgb的图像进行的
迁移VGG16部分
running_loss = 0.0
running_corrects = 0
for batch, data in enumerate(dataloader[phase], 1):
X, y = data
if Use_gpu:
X, y = Variable(X.cuda()), Variable(y.cuda())
else:
X, y = Variable(X), Variable(y)
y_pred = model(X)
_, pred = torch.max(y_pred.data, 1)
optimizer.zero_grad()
loss = loss_f(y_pred, y)
if phase == "train":
loss.backward()
optimizer.step()
running_loss += loss.data[0]
running_corrects += torch.sum(pred == y.data)
if batch%500 == 0 and phase =="train":
print("Batch {}, Train Loss:{:.4f}, Train ACC:{:.4f}".format(batch, running_loss/batch, 100*running_corrects(16*batch)))
epoch_loss = running_loss*16/len(image_datasets[phase])
epoch_acc = 100*running_corrects/len(image_datasets[phase])
print("{} Loss:{:.4f} Acc:{:.4f}%".format(phase, epoch_loss,epoch_acc))
这些行前面全部少了一个缩进
C:\Users\3057.conda\envs\pytorch11\python.exe C:/Users/lucifer/pytorch11/chp8_aut.py
Epoch:50 Style Loss: 881.223694 Content Loss:0.000000
Epoch:100 Style Loss: 881.223694 Content Loss:0.000000
Epoch:150 Style Loss: 881.223694 Content Loss:0.000000
Epoch:200 Style Loss: 881.223694 Content Loss:0.000000
Epoch:250 Style Loss: 881.223694 Content Loss:0.000000
Epoch:300 Style Loss: 881.223694 Content Loss:0.000000
Process finished with exit code 0
如题,问下训练完成后,从哪里输出迁移后的结果?
可以告知下示例代码吗?
第八章风格迁移运行的时候出现这个错误,请问该怎么解决呢??
Traceback (most recent call last):
File "C:/Users/lucifer/pytorch11/chapter_8.py", line 142, in
optimizer.step(closure)
File "C:\Users\3057.conda\envs\pytorch11\lib\site-packages\torch\optim\lbfgs.py", line 103, in step
orig_loss = closure()
File "C:/Users/lucifer/pytorch11/chapter_8.py", line 133, in closure
for cl in content_loss:
TypeError: 'Content_loss' object is not iterable
Process finished with exit code 1
It seems many code are deprecated in latest version of pytorch. Such as variables
121页
(1) 使用Numpy中的onse可以创建维度指定且元素全为1的数组
onse应该改成ones
第6章代码
loss.backward()
optimizer.step()
running_loss += loss.data[0]
running_correct += torch.sum(pred == y_train.data)
会报错
改成
loss.backward()
optimizer.step()
running_loss += loss.data
running_correct += torch.sum(pred == y_train.data)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.