7. SAVE AND LOAD MODEL

7. SAVE AND LOAD MODEL

import torch
import torchvision.models as models

7.1 保存并加载模型权重

PyTorch模型将学习到的参数存储在称为state_dict的内部字典中,并通过torch.save方法持久化:

model = models.vgg16(weights='IMAGENET1K_V1')
torch.save(model.state_dict(), 'model_weights.pth')

要加载模型权重,需要首先创建同一模型的实例,然后使用load_state_dict()方法加载参数。

model = models.vgg16() 
model.load_state_dict(torch.load('model_weights.pth'))
model.eval()

7.2 保存并加载带有形状的模型

当加载模型权重时,需要首先实例化模型类,因为该类定义了网络的结构。我们可能想将这个类的结构与模型一起保存,在这种情况下,我们可以将model传递给保存函数:

torch.save(model, 'model.pth')

可以以如下方式加载模型:

model = torch.load('model.pth')
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Enviro - The complete dynamic AAA sky and weather solution! Very easy setup: The new manager component makes it easy as possible to setup enviro in your scenes. Includes Enviro Lite! This version includes Enviro Lite version aswell. Ideal for multi-platform projects: Use lite version for low end platform like mobiles and standard for pc and consoles. With one click you can switch between enviro versions. The centralized API for your own scripts will work for both versions of course. Profile System: Enviro's new profile system makes tweaking your sky as easy as possible. Tweak settings in runtime and save to profile. Load profiles in design and runtime. Create different profiles for different scenes or share your configurations with other user. Day-Night cycle: Enviro supports a realistic day-night cycle. With correct sun and moon positions with full location support with latitude and longitude. You have options to use your system time or let enviro update time based on realtime minutes. Skybox: Enviro includes an advanced fast atmospheric skybox shader to get great looking skies! You got a lot of options to tweak the sky and even can setup funky alien skies! Lighting: Enviro will realisticly light your scene based on sun altitude. You have complete control over light intensity and color by modifying curves and gradients right in editor! You also can choose between different ambient light modes of course. Seasons: Enviro will change seasons and got a components to swap out gameobject, materials and textures of unity terrain. You are not limited to realistic settings! You can set the start and end days of each season. Enviro also supports temperature simulation, based on season, time of day and current weather. Clouds: Enviro new raymarching cloud system is based on latest cloud rendering papers. These will bring you sky to life and offer plenty options to customize. Clouds performance is optimized by using techs like temporal reprojection and LOD system. In addition there are also fast flat and particle clouds options to mix or use for maximum performance. Fog: Need stunnishing looking fog? Enviro includes an advanced light scattering fog image effect with distance, height and sky fog support. Need fog on your transparent material? No problem, with only a few lines of code you could modify your own transparent shaders to be fogged correctly. And a few particle and transparent shaders already included to get you started! Weather: Enviro includes a very powerfull weather system. You can create your own weather types and drive light, sky, fog and clouds. Enviro supports all kind of unity shuriken particle effects to give you the freedom to create any weather effect you can think of. It includes 11 premade weather types including: Clear Sky, cloudy, raining, stormy, snowy and foggy weather. You can enable lightning storms and choose different ambient and weather sounds for each weather with smooth transitions. Volumetric Lighting: Need some volume light effects you see in AAA games? No problem, enviro support volumetric lighting for directional, point and spot lights out of the box! Scene View Effects: Preview enviro effects like clouds, volume lighting and fog directly while you work on your scenes. You can enable or disable scene view preview for each effect individual of course. Networking: Enviro support UNet, Mirror and Photon out of the box. It will synchronize time and weather with all your players. Enviro also got an minimal mode for headless servers to only calculate time and weather but nothing more. Virtual Reality: Enviro supports multi and singlepass stereoscopic rendering! Tested on Oculus Rift. That's not all! Enviro includes a lot more great features: * Event system for you game logic. * Weather Zones. Create as many zones with their own weather for your biomes. * Orbiting satellites. * Vegetation Growth. And you can use a lot of awesome 3rd-party assets right of the box. Activate and add 3rd-party support through the new interface. Again its easy and fast as possible! * Gaia Compatible! * CTS Compatible! * AQUAS Integration! * LUX Water Integration! * FogVolume 3 Integration! * Vegetation Studio Pro Integration! * Playmaker Actions! * Relief Terrain Shader Integration! * UBER Shader Integration! * MicroSplat Integration! * MegaSplat Shader Integration! * Lux Shader Integration! * Photon Network Integration! * Mirror Network Integration! * Pegasus Integration! Requirements: * Support gamma and linear color space. * Support forward and deferred rendering. * Working on DX9, DX11, DX12, OpenGlCore, Metal and Vulkan. * Volumetric Lighting requires at least shader-model 3.5+ and will be deactivated on DX9 Current limitation: * Volumetric clouds are currently not suitable for fly-throughs! Will be worked on in later updates!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值