pytorch_visdom可视化

2023-10-12 11:40
文章标签 可视化 pytorch visdom

本文主要是介绍pytorch_visdom可视化,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1 pytorch show by visdom

 

 使用过程中,出现这个错误由于没有打开Visdom服务

Traceback (most recent call last):File "/home/sx/anaconda3/envs/py35/lib/python3.5/site-packages/visdom/__init__.py", line 711, in _senddata=json.dumps(msg),File "/home/sx/anaconda3/envs/py35/lib/python3.5/site-packages/visdom/__init__.py", line 677, in _handle_postr = self.session.post(url, data=data)File "/home/sx/anaconda3/envs/py35/lib/python3.5/site-packages/requests/sessions.py", line 590, in postreturn self.request('POST', url, data=data, json=json, **kwargs)File "/home/sx/anaconda3/envs/py35/lib/python3.5/site-packages/requests/sessions.py", line 542, in requestresp = self.send(prep, **send_kwargs)File "/home/sx/anaconda3/envs/py35/lib/python3.5/site-packages/requests/sessions.py", line 655, in sendr = adapter.send(request, **kwargs)File "/home/sx/anaconda3/envs/py35/lib/python3.5/site-packages/requests/adapters.py", line 516, in sendraise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8097): Max retries exceeded with url: /events (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f7565af11d0>: Failed to establish a new connection: [Errno 111] Connection refused',))

2  pip install visdom

启动visdom服务使用命令:

python -m visdom.server

观察到:

Checking for scripts.
It's Alive!
INFO:root:Application Started
You can navigate to http://localhost:8097

说明启动成功,即可访问http://localhost:8097。

3 how to use visdim ,define the Visualizer class

import visdom
import time
import numpy as np
from matplotlib import pyplot as plt
from sklearn.metrics import roc_curveclass Visualizer(object):def __init__(self, env='default', **kwargs):self.vis = visdom.Visdom(env=env, **kwargs)self.vis.close()self.iters = {}self.lines = {}def display_current_results(self, iters, x, name='train_loss'):if name not in self.iters:self.iters[name] = []if name not in self.lines:self.lines[name] = []self.iters[name].append(iters)self.lines[name].append(x)self.vis.line(X=np.array(self.iters[name]),Y=np.array(self.lines[name]),win=name,opts=dict(legend=[name], title=name))def display_roc(self, y_true, y_pred):fpr, tpr, ths = roc_curve(y_true, y_pred)self.vis.line(X=fpr,Y=tpr,# win='roc',opts=dict(legend=['roc'],title='roc'))

4 call the class

    if opt.display:visualizer = Visualizer()if opt.display:visualizer.display_current_results(iters, loss.item(), name='train_loss')visualizer.display_current_results(iters, acc, name='train_acc')

5 the result


link:https://blog.csdn.net/weixin_43290709/article/details/105937290

二、pytorch模型转换为onnx

import torch
import torchvision.models as models
resnet18 = models.resnet18(pretrained=True)
x = torch.randn(1, 3, 224, 224, requires_grad=False)# Export the model
torch.onnx.export(resnet18,                 # model being runx,                        # model input (or a tuple for multiple inputs)"resnet18.onnx",          # where to save the model (can be a file or file-like object)export_params=True,        # store the trained parameter weights inside the model fileopset_version=11,          # the ONNX version to export the model todo_constant_folding=True,  # whether to execute constant folding for optimizationinput_names = ['input'],   # the model's input namesoutput_names = ['output'], # the model's output names)

这篇关于pytorch_visdom可视化的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/195589

相关文章

Python数据分析与可视化的全面指南(从数据清洗到图表呈现)

《Python数据分析与可视化的全面指南(从数据清洗到图表呈现)》Python是数据分析与可视化领域中最受欢迎的编程语言之一,凭借其丰富的库和工具,Python能够帮助我们快速处理、分析数据并生成高质... 目录一、数据采集与初步探索二、数据清洗的七种武器1. 缺失值处理策略2. 异常值检测与修正3. 数据

Pytorch介绍与安装过程

《Pytorch介绍与安装过程》PyTorch因其直观的设计、卓越的灵活性以及强大的动态计算图功能,迅速在学术界和工业界获得了广泛认可,成为当前深度学习研究和开发的主流工具之一,本文给大家介绍Pyto... 目录1、Pytorch介绍1.1、核心理念1.2、核心组件与功能1.3、适用场景与优势总结1.4、优

使用Python和Matplotlib实现可视化字体轮廓(从路径数据到矢量图形)

《使用Python和Matplotlib实现可视化字体轮廓(从路径数据到矢量图形)》字体设计和矢量图形处理是编程中一个有趣且实用的领域,通过Python的matplotlib库,我们可以轻松将字体轮廓... 目录背景知识字体轮廓的表示实现步骤1. 安装依赖库2. 准备数据3. 解析路径指令4. 绘制图形关键

conda安装GPU版pytorch默认却是cpu版本

《conda安装GPU版pytorch默认却是cpu版本》本文主要介绍了遇到Conda安装PyTorchGPU版本却默认安装CPU的问题,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的... 目录一、问题描述二、网上解决方案罗列【此节为反面方案罗列!!!】三、发现的根本原因[独家]3.1 p

8种快速易用的Python Matplotlib数据可视化方法汇总(附源码)

《8种快速易用的PythonMatplotlib数据可视化方法汇总(附源码)》你是否曾经面对一堆复杂的数据,却不知道如何让它们变得直观易懂?别慌,Python的Matplotlib库是你数据可视化的... 目录引言1. 折线图(Line Plot)——趋势分析2. 柱状图(Bar Chart)——对比分析3

PyTorch中cdist和sum函数使用示例详解

《PyTorch中cdist和sum函数使用示例详解》torch.cdist是PyTorch中用于计算**两个张量之间的成对距离(pairwisedistance)**的函数,常用于点云处理、图神经网... 目录基本语法输出示例1. 简单的 2D 欧几里得距离2. 批量形式(3D Tensor)3. 使用不

使用Vue-ECharts实现数据可视化图表功能

《使用Vue-ECharts实现数据可视化图表功能》在前端开发中,经常会遇到需要展示数据可视化的需求,比如柱状图、折线图、饼图等,这类需求不仅要求我们准确地将数据呈现出来,还需要兼顾美观与交互体验,所... 目录前言为什么选择 vue-ECharts?1. 基于 ECharts,功能强大2. 更符合 Vue

PyTorch高级特性与性能优化方式

《PyTorch高级特性与性能优化方式》:本文主要介绍PyTorch高级特性与性能优化方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、自动化机制1.自动微分机制2.动态计算图二、性能优化1.内存管理2.GPU加速3.多GPU训练三、分布式训练1.分布式数据

Git可视化管理工具(SourceTree)使用操作大全经典

《Git可视化管理工具(SourceTree)使用操作大全经典》本文详细介绍了SourceTree作为Git可视化管理工具的常用操作,包括连接远程仓库、添加SSH密钥、克隆仓库、设置默认项目目录、代码... 目录前言:连接Gitee or github,获取代码:在SourceTree中添加SSH密钥:Cl

Pandas中统计汇总可视化函数plot()的使用

《Pandas中统计汇总可视化函数plot()的使用》Pandas提供了许多强大的数据处理和分析功能,其中plot()函数就是其可视化功能的一个重要组成部分,本文主要介绍了Pandas中统计汇总可视化... 目录一、plot()函数简介二、plot()函数的基本用法三、plot()函数的参数详解四、使用pl