一个人可以同时接纳两种相反的思想,那么就可以完成许多事|

jinganglang567

园龄:4年5个月粉丝:0关注:20

2023-09-19 16:54阅读: 4评论: 0推荐: 0

pytorch学习了解

import torchvision
from model1test import *
from torch.utils.data import DataLoader
from torch.utils.tensorboard import SummaryWriter

trian_data=torchvision.datasets.CIFAR10('./datasets',train=True,transform=torchvision.transforms.ToTensor())
test_data=torchvision.datasets.CIFAR10('./datasets',train=False,transform=torchvision.transforms.ToTensor())

print('训练集长度 {}'.format(len(trian_data)))
print('测试集长度 {}'.format(len(test_data)))

traindata_loader=DataLoader(trian_data,batch_size=64)
testdata_loader=DataLoader(test_data,batch_size=64)

# 创建模型
mymodel1=mymodel()
if torch.cuda.is_available():
    mymodel1=mymodel1.cuda()

# 创建损失函数
loss_fn=nn.CrossEntropyLoss()
loss_fn=loss_fn.cuda()
# 创建优化器
learing_rate=0.001
optimzer=torch.optim.SGD(mymodel1.parameters(),lr=learing_rate)


# 开始训练
# 训练次数
total_train_step=0

# 测试次数

total_test_step=0
writer=SummaryWriter('first-train')
# 训练轮数
epoch=10
for i in range(epoch):
    print('第{}轮'.format(i+1))
#     开始训练
    for data in traindata_loader:
        imgs,targets=data
        imgs=imgs.cuda()
        targets=targets.cuda()
#         用模型训练
        outputs=mymodel1(imgs)

#         计算损失
        loss=loss_fn(outputs,targets)

#         优化器优化
        optimzer.zero_grad()
        loss.backward()
        optimzer.step()
#         总步数
        total_train_step+=1
        if total_train_step % 100 ==0:
            print('训练次数{},loss{}'.format(total_train_step,loss.item()))
            writer.add_scalar('train',loss.item(),total_train_step)

    # 开始测试模型
    total_test_loss=0
    with torch.no_grad():
        for data in testdata_loader:
            imgs,targets=data
            imgs=imgs.cuda()
            targets=targets.cuda()
            outputs=mymodel1(imgs)
            loss=loss_fn(outputs,targets)
            total_test_loss=total_test_loss+loss
    print('整体测试集{}'.format(total_test_loss))

    writer.add_scalar('test',total_test_loss.item(),total_test_step)
    total_test_step+=1

    torch.save(mymodel1,'number{}'.format(i))



writer.close()

本文作者:jinganglang567

本文链接:https://www.cnblogs.com/tgfoven/p/17715140.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   jinganglang567  阅读(4)  评论(0编辑  收藏  举报
  1. 1 look after you louis tomlinson
  2. 2 just hold on louis tomlinson
  3. 3 i can steven cooper
  4. 4 rock me one direction
  5. 5 just can't let her go one direction
  6. 6 this town Niall Horan
  7. 7 cut in love july
  8. 8 nemo 夜愿
  9. 9 in the end Black Veil Brides
  10. 10 glad you came the wanted
  11. 11 chasing the sun the wanted
  12. 12 TAKE MY HAND simple plan
  13. 13 wish i had an angel 夜愿
i can - steven cooper
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.

作曲 : Steven D Cooper

Seems like nowadays, everybody lacks patience

Want it right now, always sick of this waiting

Hating on anyone, stuck in the process

For God sakes, how long will you waste, it's non sense

Telling you to give up on the dream, but who

Are they to throw away, all their faith in you

No way you're gonna fade, let them say and shoo

Get away, 'cause what they say don't have weight with you

You keep moving on, write that, do a song

Right track, you belong, fight back, prove them wrong

Yeah, just keep on, keeping on

Yeah, 'cause this track you be on

Right there's gotta lot of potential

So never give up, just sharpen your pencil

Close out all the negative talk

Put on those old shoes and choose where you walk

When you fall, stand up

And when you break, stand tough

And when they say, you can't

You say I can, I can

When you fall, stand up

And when you break, stand tough

And when they say, you can't

You say I can, I can

Don't lose faith, 'cause the minute you break

Is the minute you wake, with a million mistakes

And a million regrets that, you'll never get back

The time that you set back, to please other friends that

Tell you that you can't be what you wanna be

There's a world out there go and see what you wanna see

I've been there, I can relate

So let this song tell ya that it's never too late

Wide awake, and I see more than ever

That people are quick to give up on their endeavors

Never really try 'cause they're scared of failure

So, allow me to be the first to tell ya'

I've failed more times than I've succeeded

In the end, exactly what I needed

To allow me to learn the right steps

So I'd never go back, and I never regret

When you fall, stand up

And when you break, stand tough

And when they say, you can't

You say I can, I can

When you fall, stand up

And when you break, stand tough

And when they say, you can't

You say I can, I can

A lot of dreams get left at the wayside

And I can feel their death in the baseline

'Cause of something' someone once said

At once dead,

Don't let them stop you in your tracks, at once dead

Say to yourself, I'ma be stronger than

Stay up late everyday working harder than

Keep my head focused, stick to the plan

They say I can't but I say I can

When you fall, stand up

And when you break, stand tough

And when they say, you can't

You say I can, I can

When you fall, stand up

And when you break, stand tough

And when they say, you can't

You say I can, I can

点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起