【数据处理】pth文件读取

读取模型训练的.pth文件,并利用其读取图片特征 以下就是我保存的其中一个epoch的模型训练参数的文件,是.pth文件。 阅读详情

1. 数据处理

首先将json文件(如下),经过一系列处理好保存在trainset.pth文件中

1.1 json文件数据预处理----trainset.pth文件

        self.path_trainset = osp.join(self.subdir_processed, 'trainset.pth') #将vqa2.0json文件处理好后存放的地方

    def process(self):
        dir_ann = osp.join(self.dir_raw, 'annotations')
        path_train_ann = osp.join(dir_ann, 'mscoco_train2014_annotations.json')
        path_train_ques = osp.join(dir_ann, 'OpenEnded_mscoco_train2014_questions.json')
        train_ann = json.load(open(path_train_ann))
        train_ques = json.load(open(path_train_ques))
        trainset = self.merge_annotations_with_questions(train_ann, train_ques) #合并答案和question文件
        trainset = self.add_image_names(trainset) #向文件中添加图像名
        trainset['annotations'] = self.add_answer(trainset['annotations']) #向文件中添加答案
        trainset['annotations'] = self.tokenize_answers(trainset['annotations']) #对答案进行tokenize处理
        trainset['questions'] = self.tokenize_questions(trainset['questions'], self.nlp) #对问题采用nlp进行tokenize处理
        trainset['questions'] = self.insert_UNK_token(trainset['questions'], wcounts, self.minwcount)
        trainset['questions'] = self.encode_questions(trainset['questions'], word_to_wid)
        trainset['annotations'] = self.encode_answers(trainset['annotations'], ans_to_aid)
        torch.save(trainset, self.path_trainset) #保存处理好后的json文件到trainset.pth中
#加载数据集
if not os.path.exists(self.subdir_processed):
	self.process()      
self.dataset = torch.load(self.path_trainset)

在这里插入图片描述
’questions’
在这里插入图片描述
’annotations’
在这里插入图片描述

1.2 获取faster-rcnn提取好的图像特征信息

    #添加rcnn提取的信息
    def add_rcnn_to_item(self, item):
        '''
        :param item: 传入的coco/extract/coco_train*******.jpg.pth文件
        :return:
        '''
        path_rcnn = os.path.join(self.dir_rcnn, '{}.pth'.format(item['image_name']))
        item_rcnn = torch.load(path_rcnn) #加载pth文件
        print(item_rcnn)
        item['visual'] = item_rcnn['pooled_feat'] #区域特征
        item['coord'] = item_rcnn['rois'] #感兴趣区域位置
        item['norm_coord'] = item_rcnn['norm_rois'] #感兴趣区域特征标准化
        item['nb_regions'] = item['visual'].size(0) #区域数
        return item

在这里插入图片描述

1.3 向传入模型的数据中添加1.1处理好的trainset.pth信息和faster-rcnn提取好的图像特征信息

    def __getitem__(self, index):
        item = {}
        item['index'] = index

        # Process Question (word token)
        question = self.dataset['questions'][index]
        if self.load_original_annotation:
            item['original_question'] = question

        item['question_id'] = question['question_id'] #向item中添加问题id:question_id
        item['question'] = torch.LongTensor(question['question_wids']) #向item添加问题单词索引表示:question
        item['lengths'] = torch.LongTensor([len(question['question_wids'])]) #向item添加问题长度:lengths
        item['image_name'] = question['image_name'] #向item添加图像名:image_name

        # Process Object, Attribut and Relational features
        # 处理对象、特性和关系特征
        item = self.add_rcnn_to_item(item) #向item中添加由faster-rcnn提取好的图像特征信息 :boxes,feature

        # 如果答案存在,处理答案(主要是因为测试集没有答案,所有处理训练集)
        if 'annotations' in self.dataset:
            annotation = self.dataset['annotations'][index]
            if self.load_original_annotation:
                item['original_annotation'] = annotation
            if 'train' in self.split and self.samplingans:
                proba = annotation['answers_count']
                proba = proba / np.sum(proba)
                item['answer_id'] = int(np.random.choice(annotation['answers_id'], p=proba))
            else:
                item['answer_id'] = annotation['answer_id']
            item['class_id'] = torch.LongTensor([item['answer_id']])
            item['answer'] = annotation['answer']
            item['question_type'] = annotation['question_type']
        else:
            if item['question_id'] in self.is_qid_testdev:
                item['is_testdev'] = True
            else:
                item['is_testdev'] = False
        return item

整个item字典中键有

{
index :索引,
question_id:问题id,458752001
question:问题, tensor([4321, 2932, 1997, 3968, 2286, 2878])
lengths:问题长度, tensor([6]), 
image_name:图像名,'COCO_train2014_000000458752.jpg'
visual:图像特征,
coord:感兴趣区域位置信息,
norm_coord:感兴趣区域位置信息标准化,
nb_regions:区域数,36
answer_id:答案id,382
class_id:分类id, tensor([382])
answer:答案,'pitcher'
question_type:问题类型  'what'
}

如下item数据具体信息:

{		'index': 1, 
		'question_id': 458752001,
		 'question': tensor([4321, 2932, 1997, 3968, 2286, 2878]), 'lengths': tensor([6]), 
		 'image_name': 'COCO_train2014_000000458752.jpg', 
		 'visual': tensor([[0.0000, 0.0000, 0.0231,  ..., 0.0000, 0.0281, 1.5262],
        [0.0000, 0.0169, 0.0587,  ..., 0.0000, 0.0064, 1.1313],
        [0.3978, 0.0000, 0.0000,  ..., 0.0000, 0.1113, 3.8770],
        ...,
        [0.0326, 0.0000, 0.0000,  ..., 0.0799, 2.7793, 1.2371],
        [0.0000, 0.0000, 0.0000,  ..., 0.0000, 0.0000, 0.3857],
        [0.0084, 0.8026, 0.0966,  ..., 0.0000, 0.7668, 0.0798]]), 
        
        'coord': tensor([[282.9814, 302.8545, 372.2248, 468.0808],
        [311.6291, 333.7408, 359.6907, 358.5282],
        [215.0726, 172.1102, 352.8074, 407.3577],
        [285.7687, 189.5694, 329.6428, 231.0218],
        [274.9748, 160.3990, 318.7502, 208.2673],
        [241.7279, 302.4235, 286.6740, 342.9375],
        [241.9454, 230.9683, 355.9464, 350.7243],
        [  0.0000,   0.0000, 383.6760, 425.9977],
        [372.8926, 360.4357, 629.3776, 401.7158],
        [348.9116,  45.5669, 639.2000, 479.2000],
        [391.1129, 149.4865, 610.5438, 353.4078],
        [ 28.7101, 178.1590, 235.1222, 398.0370],
        [353.4412, 420.1210, 381.8891, 442.3383],
        [249.2581, 316.8993, 319.8651, 357.7612],
        [  0.0000,   0.0000, 487.8425, 174.9353],
        [177.7185,  63.3202, 472.4503, 479.2000],
        [  6.3949, 120.7137, 639.2000, 479.2000],
        [ 88.5412, 209.1507, 558.1020, 479.2000],
        [254.3652, 164.8777, 332.2064, 206.6262],
        [189.8386, 128.2660, 426.3345, 479.2000],
        [237.2819, 281.1407, 411.9520, 479.2000],
        [ 20.9822, 370.2453, 301.8062, 402.6493],
        [312.2184, 263.2010, 344.6071, 296.3635],
        [265.3174, 229.0582, 374.0845, 349.4183],
        [257.8582, 154.3860, 341.2274, 235.9603],
        [108.7576, 342.0231, 573.0241, 455.5504],
        [ 57.4191,   0.0000, 617.8732, 117.8669],
        [234.5487, 271.3556, 268.1855, 318.8475],
        [323.6842,   0.0000, 639.2000, 145.7849],
        [263.1414, 249.6308, 396.5386, 479.2000],
        [310.9734, 257.4800, 349.8676, 292.9267],
        [349.4448, 423.4623, 388.5869, 452.1093],
        [269.6038, 153.9579, 300.1459, 188.4087],
        [162.7299,   0.0000, 639.2000, 230.7880],
        [286.1820, 371.8325, 346.1609, 479.2000],
        [168.0096, 305.8445, 479.0755, 479.2000]]), 
        'norm_coord': tensor([[0.4422, 0.6309, 0.5816, 0.9752],
        [0.4869, 0.6953, 0.5620, 0.7469],
        [0.3361, 0.3586, 0.5513, 0.8487],
        [0.4465, 0.3949, 0.5151, 0.4813],
        [0.4296, 0.3342, 0.4980, 0.4339],
        [0.3777, 0.6300, 0.4479, 0.7145],
        [0.3780, 0.4812, 0.5562, 0.7307],
        [0.0000, 0.0000, 0.5995, 0.8875],
        [0.5826, 0.7509, 0.9834, 0.8369],
        [0.5452, 0.0949, 0.9988, 0.9983],
        [0.6111, 0.3114, 0.9540, 0.7363],
        [0.0449, 0.3712, 0.3674, 0.8292],
        [0.5523, 0.8753, 0.5967, 0.9215],
        [0.3895, 0.6602, 0.4998, 0.7453],
        [0.0000, 0.0000, 0.7623, 0.3644],
        [0.2777, 0.1319, 0.7382, 0.9983],
        [0.0100, 0.2515, 0.9988, 0.9983],
        [0.1383, 0.4357, 0.8720, 0.9983],
        [0.3974, 0.3435, 0.5191, 0.4305],
        [0.2966, 0.2672, 0.6661, 0.9983],
        [0.3708, 0.5857, 0.6437, 0.9983],
        [0.0328, 0.7713, 0.4716, 0.8389],
        [0.4878, 0.5483, 0.5384, 0.6174],
        [0.4146, 0.4772, 0.5845, 0.7280],
        [0.4029, 0.3216, 0.5332, 0.4916],
        [0.1699, 0.7125, 0.8954, 0.9491],
        [0.0897, 0.0000, 0.9654, 0.2456],
        [0.3665, 0.5653, 0.4190, 0.6643],
        [0.5058, 0.0000, 0.9988, 0.3037],
        [0.4112, 0.5201, 0.6196, 0.9983],
        [0.4859, 0.5364, 0.5467, 0.6103],
        [0.5460, 0.8822, 0.6072, 0.9419],
        [0.4213, 0.3207, 0.4690, 0.3925],
        [0.2543, 0.0000, 0.9988, 0.4808],
        [0.4472, 0.7747, 0.5409, 0.9983],
        [0.2625, 0.6372, 0.7486, 0.9983]]),
         'nb_regions': 36, 
         'answer_id': 382, 
         'class_id': tensor([382]),
          'answer': 'pitcher', 
          'question_type': 'what'}
PyTorch中.pth文件的解析及应用 pth文件是PyTorch中用于保存和加载模型参数的标准文件格式。它不仅可以存储模型的权重(如各层的参数、偏置等),还能保存优化器状态、训练进度(如当前epoch、损失值)等元数据。通过.pth文件,开发者能够快速保存训练好的模型,并在后续任务中复用或恢复训练,避免重复计算资源消耗。在深度学习中,模型训练通常耗时较长。使用.pth文件保存中间状态或最终模型,可显著提升开发效率,尤其适用于迁移学习、模型部署和协作共享等场景。.pth。 阅读详情

相关推荐

点云可视化:使用Python进行点云数据处理与可视化

点云数据是一种三维空间中的离散点集合,广泛应用于计算机视觉、机器人学和地理信息系统等领域。点云可视化是将点云数据以直观的图形方式呈现,便于我们理解和分析数据的空间分布特征。本文将介绍如何使用Python进行点云数据的处理和可视化。通过加载点云数据、进行各种操作和运用不同的函数,我们可以更深入地了解点云数据的特性,并将其直观地呈现出来。希望本文能够帮助你入门点云数据处理与可视化领域,让你能够更好地利用点云数据进行科学研究和实际应用。除了简单的加载和可视化外,我们还可以对点云数据进行各种处理和操作。

UePostscript的博客 864

.pt/pth 文件读取

import torch path='/media/workstation/4.0T/master/model.pth' pretrained_dict = torch.load(path) for k, v in pretrained_dict.items(): # k 参数名 v 对应参数值 print(k)

weixin_54275159的博客 1504

子网划分详解

还不会子网划分?看这篇就够了,保姆级教程

m0_47584619的博客 6093

pytorch读取.pth文件

1.pth文件中保存的是什么 import torch state_dict = torch.load("resnet18.pth") print(type(state_dict)) --------------- <class 'collections.OrderedDict'> 如上打印输出所示,pth文件通过有序字典来保持模型参数。有序字典与常规字典一样,但是在排序操作方面有一些额外的功能。常规的dict是无序的,OrderedDict能够比dict更好地处理频繁的重新排序操作。

蒲建建 2万+

医疗大模型实战——从零构建MedicalGPT全流程解析

本文详细解析了从零构建医疗大模型MedicalGPT的全流程实战。基于Qwen-7B模型与约195万条中文医疗数据,完整复现了增量预训练、监督微调与偏好对齐三大核心环节,并分享了如何在有限硬件资源下实现高效训练与部署,为开发者提供了可复现的医疗AI项目实战指南。

weixin_29193259的博客 556

superpowers-中文使用说明

《obra/superpowers:AI辅助开发的流程纪律工具集》 摘要:obra/superpowers是一套面向AI辅助软件开发的系统化流程规范,包含14个核心技能,强调"先理解后行动"的纪律性开发方法。该工具集定义了从头脑风暴到代码评审的完整工作流,要求严格遵循测试驱动开发、子代理隔离执行等原则。核心特色包括:1) 任何实现前必须完成设计和评审;2) 采用红-绿-重构的TDD循环;3) 复杂任务通过独立子代理串行处理;4) 所有产出需经过双重验证(规格合规+代码质量)。该工具集特别注重文档化和可验证性

qq_22786633的博客 767

Python查看.pth后缀文件!!(后缀为.pth的重要文件查看方法!!!)

Python查看.pth后缀文件!!(后缀为.pth的重要文件查看方法!!!)

weixin_45325693的博客 2万+

DSP28335学习笔记——McBSP配置为SPI

由于28335硬件外设上只有一个SPI接口,所以当SPI接口不够用时,可以将McBSP配置为SPI接口。 参考28335的数据手册,当DSP为主机时,配置McBSP为SPI所用到的接线如下图所示。 另外总结一些调试过程中的经验。 1.传输数据位数的确定 由RCR1寄存器中的RWDLEN1和XCR1寄存器中的XWDLEN1决定。分别对应着接受和发送的位数,在配置成SPI模式的时候,这

捕虫少年 1万+

Python 读取和写入文件的方法【文本文件(txt),Excel 文件,JSON 文件,pth文件,npy文件】

python 文本文件 excel文件 json文件 pth文件 npy文件 读取 写入

weixin_44151034的博客 1462

2025东方财富笔试考什么?cata能力测评攻略|答题技巧真题分享

4月10日-4月20日 专业笔试(行测+金融知识混合双打) 4月25日-5月10日 面试车轮战(AI面+半结构化+压力面) 5月15日起 Offer发放(谈薪必杀技:对标同花顺/雪球)这里不仅是金融极客的乐园,更是**“年薪30万管培生计划”**的主战场——你将用代码重构K线,用算法预判市场,成为资本市场的“数字先知”。东方财富,中国金融信息服务领域的“隐形冠军”,以**“金融数据+互联网”双擎驱动**,打造了覆盖证券、基金、期货的全生态交易平台。:• “我总坚持自己的方案”(HR:团队毒药!

Dgntsj的博客 3262

PCIe中ACS知识小记

虚拟机内部的访问数据显而易见是带的GPA地址。而目前几乎所有的PCIe 设备都带ACS control,所以它们可以单独assign给不同的VM,但是随之而来的就是即使两个GPU同时assign给同一个VM,由于ACS的存在,他们之间也不会有真正的物理层面的P2P访问。每一个TLP都自带一个address(寻址类TLP),同时每一个endpoint,PCIe switch都自带一段BIOS配置的地址空间范围,一旦这个TLP的address落入某个设备的地址范围,那么这个TLP就属于这个设备并消费。

Summer的博客 5078

Python .pth文件安全风险解析:从模块路径配置到权限提升后门

Python模块导入机制是理解其生态运行的基础,解释器通过sys.path列表搜索模块,其中site-packages目录是关键路径。site模块在启动时会自动加载站点目录下的.pth文件,这一设计初衷是为了灵活管理模块搜索路径。然而,当.pth文件内容以import开头时,其中的Python代码会被直接执行,这赋予了它在特定场景下的技术价值:实现自动化环境配置。在安全领域,这一特性可能被滥用于权限提升和持久化攻击,尤其是在拥有站点目录写入权限的场景下。攻击者可以植入恶意代码,在Python进程启动时自动执

weixin_34405557的博客 615

YOLO格式数据集【数据增强】终极脚本 | 70+种顶级数据增强方法 | 可带标签增强

YOLO格式数据集【数据增强】终极脚本 | 70+种顶级数据增强方法 | 可带标签增强

Coding... 5502

探寻C++最快的读取文件的方案

在竞赛中,遇到大数据时,往往读文件成了程序运行速度的瓶颈,需要更快的读取方式。相信几乎所有的C++学习者都在cin机器缓慢的速度上栽过跟头,于是从此以后发誓不用cin读数据。还有人说Pascal的read语句的速度是C/C++中scanf比不上的,C++选手只能干着急。难道C++真的低Pascal一等吗?答案是不言而喻的。一个进阶的方法是把数据一下子读进来,然后再转化字符串,这种方法传说中很不错,

教兽之家 809

K-Core, K-Shell & K-Crust傻傻分不清楚

K-Core(K-核)就是所有大于等于K的K-Shell的并集;K-Crust(K-皮)就是所有小于等于K的K-shell的并集。

欢迎订阅 -- 小源笔迹 2256

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

tensorflow文件读取

1、知识点 """ 注意:在tensorflow当中,运行操作具有依赖性 1、CPU操作计算与IO计算区别: CPU操作: 1、tensorflow是一个正真的多线程,并行的执行任务 2、使用tfrecords对文件读取进行改善 IO操作: 1...

weixin_30810583的博客 103

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

numpy数据存储和读取以及操作

今天老师让把两种模型训练的结果PR曲线画到一张图里,这土狗一下子就蒙了好吗,我很清楚的知道要存储的信息可不是一般的数据,最终还是向列表以为帅气又善良的小哥哥求救了 以下就是正式操作了 1.首先原代码里是在验证阶段定义了两个空列表(每个epoch都要验证一次,这两个空列表就定义在验证阶段之前) # 验证阶段 if (epoch+1) % val_interval == 0: correct_val = 0. total_val = 0.

weixin_42855400的博客 819

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

python 2.7导入arcpy_科学网-Python2.7同时导入arcpy和gdal-温兆飞的博文

科学网-Python2.7同时导入arcpy和gdal-温兆飞的博文

weixin_39994438的博客 372

pytorch模型保存格式

pytorch保存数据 保存用到torch.save函数,注意该函数第一个参数可以是单个值也可以是字典,字典可以存更多你要保存的参数(不仅仅是权重数据) pytorch读取数据 pytorch读取数据使用的方法和我们平时使用预训练参数所用的方法是一样的,都是使用load_state_dict这个函数。 三个核心功能(保存和加载模型) 1.torch.save:将序列化的对象保存到disk。这个函数...

zls 9863

FacePose_pytorch安全与隐私考量:面部数据处理的最佳实践指南

FacePose_pytorch是一个基于PyTorch实现的实时头部姿态估计(偏航角、滚动角、俯仰角)和情感检测项目,具有业界领先的性能表现。在当今人工智能技术快速发展的时代,面部数据处理的安全与隐私保护已成为开发者和用户共同关注的核心问题。本文将深入探讨在使用FacePose_pytorch进行面部数据分析时应遵循的最佳安全实践,确保您的应用既高效又合规。 ## 📊 面部数据处理的安全挑战

gitblog_07073的博客 413

h5页面保存img_pytorch模型保存格式

对着手写数字识别实例讲讲pytorch模型保存的格式。首先讲讲保存模型或权重参数的后缀格式,权重参数和模型参数的后缀格式一样,pytorch中最常见的模型保存使用 .pt 或者是 .pth 作为模型文件扩展名。还有其他的保存数据的格式为.t7或者.pkl格式。t7文件是沿用torch7中读取模型权重的方式,而pth文件是python中存储文件的常用格式,而在keras中则是使用.h5文件 。1、p...

weixin_35545176的博客 511

Python学习之路之抓取数据并绘图

Python 的学习之路: Python的名声早就如雷贯耳,多次占据编程语言top1的宝座,以用于各种场景,然而一个自律性并不强的人并不想花费大量的精力学习一个用不上的语言。 偏偏最近由于项目上需要对大量的数据做分析处理,于是便抽出一天时间学习了python画图和数据读取部分的内容。 关于python的注意事项总结: 1. 代码中省去了C,C++中的括号,或者SV中的begin end, 也正因如此,Python对缩进要求更严格。 2. for 循环格式 3. 代码行尾部没有分号 场景: 验证平台进行上千

qq_32404185的博客 1390

pytorch不加载fc_pytorch 加载部分预训练网络 预训练网络比正在训练的网络大 完整直接能跑案例...

当然说是直接能跑,首先你要有torch第一个文件,生成存储网络参数的pth文件网络是预测一个sin函数,全连接,1 20 20 1# -*- coding: utf-8 -*-"""Created on Mon Jul 27 16:47:37 2020学习PyTorch中使用预训练的模型初始化网络的一部分参数(增减网络层,修改某层参数等) 固定参数https://discuss.pytorch.o...

weixin_32558567的博客 263

C++调用python获取wav文件信息

同事提供了分析音频的python接口,我需要集成到C++服务中,以下是将wav文件传输给python并获取返回结果的一种方式 1.wav文件格式 WAV是符合RIFF标准的多媒体文件,其文件结构可以如下: WAV 文件结构 RIFF块 WAVE FOURCC fmt 块 fact 块(可选) data块(包含PCM数据) 分析一段音频除了需要音频的PCM数据,还需要获取音频的采样率,比特类型,声道等信息。同事的python代码通过导入wave模块获取.wav文件的信息。但对于.

jianhui777的博客 527

【轩说Pytorch】卷积神经网络项目 动物识别系统 图片分类系统(附源码)

加载已经训练好的模型参数,并调用test来测试图片分类结果。随机给照片,让其分类,把照片放入demo/input中,我们从demo/output/result.csv中输出对应照片的分类结果。.在pytorch的optim优化器中,可以传入权重衰减的权重,配置文件里给到了0.00001,可见,虽然进行权重衰减,但是不宜太过。通过遍历数据集来检测并删除错误的数据(有可能看起来是正常的图片,但是读到网络里就会有异常抛出)–dirs 返回的是一个列表list,是该文件夹中所有的目录的名称(但不包括子目录名称)

m0_57089390的博客 1772

RVC开源项目深度解析:代码结构、模型权重格式、ONNX导出支持

本文深度解析了RVC开源项目的代码结构、模型权重格式及ONNX导出支持。借助星图GPU平台,用户可以自动化部署RVC镜像,快速搭建语音转换环境。该镜像的核心应用场景是AI音色转换,能够将输入的音频转换为特定目标音色,广泛应用于内容创作、语音合成等领域。

weixin_36074800的博客 254
上一篇: 【数据处理】之读取csv文件报错
下一篇: 视觉问答项目
snow5618
博客等级 码龄9年 141粉丝 51原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值