网站制作的大公司网站建设分为那几个模块
网站制作的大公司,网站建设分为那几个模块,台州网站建设方案优化,沈阳免费自助建站模板一、安装TensorBoard
管理员身份运行Anaconda Prompt#xff0c;进入自己的环境环境 conda activate y_pytorch#xff0c;pip install tensorboard 进行下载#xff0c;也可以通过conda install tensorboard进行下载。其实通俗点#xff0c;pip相当于菜市场#xff0c;c…一、安装TensorBoard
管理员身份运行Anaconda Prompt进入自己的环境环境 conda activate y_pytorchpip install tensorboard 进行下载也可以通过conda install tensorboard进行下载。其实通俗点pip相当于菜市场conda相当于大型正规超市。
二、SummaryWriter类
所有编译均在PyChram下进行
from torch.utils.tensorboard import SummaryWriter按着Ctrl点击SummaryWriter进入查看该类的使用说明文档 Writes entries directly to event files in the log_dir to beconsumed by TensorBoard. 将条目直接写入log_dir中的事件文件供TensorBoard使用The SummaryWriter class provides a high-level API to create an event filein a given directory and add summaries and events to it. The class updates thefile contents asynchronously. This allows a training program to call methodsto add data to the file directly from the training loop, without slowing downtraining.看不懂没关系DL翻译一下就行了呗大概就是SummaryWriter类会生成一个文件这个文件会被TensorBoard所解析使用也就是说可以通过TensorBoard进行可视化展示#这个是SummaryWriter的初始化函数def __init__(self, log_dirNone, comment, purge_stepNone, max_queue10,flush_secs120, filename_suffix):Creates a SummaryWriter that will write out events and summariesto the event file.Args:log_dir (string): Save directory location. Default isruns/**CURRENT_DATETIME_HOSTNAME**, which changes after each run.Use hierarchical folder structure to comparebetween runs easily. e.g. pass in runs/exp1, runs/exp2, etc.for each new experiment to compare across them.
#保存的文件为log_dir所指定的位置默认为runs/**CURRENT_DATETIME_HOSTNAME**这个位置#同理后面的参数可以进行翻译然后进行学习即可comment (string): Comment log_dir suffix appended to the defaultlog_dir. If log_dir is assigned, this argument has no effect.purge_step (int):When logging crashes at step :math:TX and restarts at step :math:T,any events whose global_step larger or equal to :math:T will bepurged and hidden from TensorBoard.Note that crashed and resumed experiments should have the same log_dir.max_queue (int): Size of the queue for pending events andsummaries before one of the add calls forces a flush to disk.Default is ten items.flush_secs (int): How often, in seconds, to flush thepending events and summaries to disk. Default is every two minutes.filename_suffix (string): Suffix added to all event filenames inthe log_dir directory. More details on filename construction intensorboard.summary.writer.event_file_writer.EventFileWriter.Examples::
#如何使用使用案例from torch.utils.tensorboard import SummaryWriter# create a summary writer with automatically generated folder name.writer SummaryWriter()# folder location: runs/May04_22-14-54_s-MacBook-Pro.local/
#参数啥都不加默认生成的文件会放入runs/May04_22-14-54_s-MacBook-Pro.local/位置# create a summary writer using the specified folder name.writer SummaryWriter(my_experiment)# folder location: my_experiment
#指定位置生成的文件会放入指定位置# create a summary writer with comment appended.writer SummaryWriter(commentLR_0.1_BATCH_16)# folder location: runs/May04_22-14-54_s-MacBook-Pro.localLR_0.1_BATCH_16/了解完SummaryWriter之后开始为其创建对象
writer SummaryWriter(y_log)#对应生成的文件会放入y_log文件夹下三、add_scalar()方法
将标量数据添加到summary中
writer.add_scalar()#按住Ctrl点击add_scalar方法查看该方法的使用说明Add scalar data to summary.
#将标量数据添加到summary中Args:#参数tag (string): Data identifier
#图标的title名称scalar_value (float or string/blobname): Value to save
#要保存的数据值一般用作y轴global_step (int): Global step value to record
#记录全局的步长值一般用作x轴walltime (float): Optional override default walltime (time.time())with seconds after epoch of eventnew_style (boolean): Whether to use new style (tensor field) or oldstyle (simple_value field). New style could lead to faster data loading.Examples::from torch.utils.tensorboard import SummaryWriterwriter SummaryWriter()x range(100)for i in x:writer.add_scalar(y2x, i * 2, i)writer.close()Expected result:.. image:: _static/img/tensorboard/add_scalar.png:scale: 50 %绘制一个y3*x的图通过tensorboard进行展示
from torch.utils.tensorboard import SummaryWriterwriter SummaryWriter(y_log)#文件所存放的位置在y_log文件夹下for i in range(100):writer.add_scalar(y3*x,3*i,i)#图标的title为y3*xy轴为3*ix轴为i
#要注意的是title若一样则会发生拟合现象会出错。一般不同图像要对应不同的title一个title会对应一张图。writer.close()运行完之后发现多了个文件夹里面存放的就是tensorboard的一些事件文件 在Terminal下运行tensorboard --logdiry_log --port7870logdir为打开事件文件的路径port为指定端口打开 通过指定端口7870进行打开tensorboard若不设置port参数默认通过6006端口进行打开。 点击该链接或者复制链接到浏览器打开即可
四、add_image()方法
将图像数据添加到summary中 同样的道理进行查看该方法的使用说明
writer.add_image()#按住Ctrl点击aadd_image方法查看该方法的使用说明Add image data to summary.
#将图像数据添加到summary中Note that this requires the pillow package.Args:#参数tag (string): Data identifier
#对数据的定义也就是在tensorboard中显示的时候title是啥 img_tensor (torch.Tensor, numpy.array, or string/blobname): Image data
#这里对图像的要求必须是这几类需要将图片类型进行转换global_step (int): Global step value to record
#记录的全局步长也就是第几张图片walltime (float): Optional override default walltime (time.time())seconds after epoch of eventShape:img_tensor: Default is :math:(3, H, W). You can use torchvision.utils.make_grid() toconvert a batch of tensor into 3xHxW format or call add_images and let us do the job.Tensor with :math:(1, H, W), :math:(H, W), :math:(H, W, 3) is also suitable as long ascorresponding dataformats argument is passed, e.g. CHW, HWC, HW.
##图片的类型应该为(3, H, W)若不一样则可以通过dataformats参数进行设置Examples::from torch.utils.tensorboard import SummaryWriterimport numpy as npimg np.zeros((3, 100, 100))img[0] np.arange(0, 10000).reshape(100, 100) / 10000img[1] 1 - np.arange(0, 10000).reshape(100, 100) / 10000img_HWC np.zeros((100, 100, 3))img_HWC[:, :, 0] np.arange(0, 10000).reshape(100, 100) / 10000img_HWC[:, :, 1] 1 - np.arange(0, 10000).reshape(100, 100) / 10000writer SummaryWriter()writer.add_image(my_image, img, 0)# If you have non-default dimension setting, set the dataformats argument.writer.add_image(my_image_HWC, img_HWC, 0, dataformatsHWC)writer.close()Expected result:.. image:: _static/img/tensorboard/add_image.png:scale: 50 %添加图片到tensorboard中
from torch.utils.tensorboard import SummaryWriter
import cv2 as cv
import numpy as npwriter SummaryWriter(y_log)img_path G:/PyCharm/workspace/learning_pytorch/dataset/a/1.jpg
img cv.imread(img_path)
img_array np.array(img)
print(type(img_array))#class numpy.ndarray 满足该方法img_tensor类型
print(img_array.shape)#(499, 381, 3) 这里看到是(H, W, 3)并不是人家指定的(3, H, W)需要设置dataformats来声明该数据规格为HWCwriter.add_image(beyond,img_array,0,dataformatsHWC)#将来在tensorbord显示的title为beyondwriter.close()在Terminal下运行tensorboard --logdiry_log --port7870logdir为打开事件文件的路径port为指定端口打开 通过指定端口7870进行打开tensorboard若不设置port参数默认通过6006端口进行打开。 点击该链接或者复制链接到浏览器打开即可
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/92431.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!