当前位置: 首页 > news >正文

怎么看一个网站做外链专业的深圳网站建设公司排名

怎么看一个网站做外链,专业的深圳网站建设公司排名,郑州seo阿伟,石家庄做网站wsjztransform是torchvision下的一个.py文件#xff0c;这个python文件中定义了很多的类和方法#xff0c;主要实现对图片进行一些变换操作 一、Transforms讲解 from torchvision import transforms#按着Ctrl#xff0c;点击transforms进入到__init__.py文件中 from .transfo…transform是torchvision下的一个.py文件这个python文件中定义了很多的类和方法主要实现对图片进行一些变换操作 一、Transforms讲解 from torchvision import transforms#按着Ctrl点击transforms进入到__init__.py文件中 from .transforms import *#再次按着Ctrl点击.transforms from .autoaugment import *进入transform.py文件中可以看到transforms其实就是transform.py一个python文件可以理解为其是一个工具包 点击Structure或Alt7查看下这个文件的大概结构框架 File–Settings–keymap–structure可以查看快捷键 通俗点transform指的就是transform.py文件该文件里面有好多类可以对图像进行各种各样的操作 二、ToTensor类 看下文档给的使用说明 CtrlP显示方法所需要的参数 Convert a PIL Image or numpy.ndarray to tensor. This transform does not support torchscript. #可以看到其实就将PIL Image、numpy.ndarray类型的图片转换为tensor类型 #PIL针对的是Python自带的Image进行open操作numpy.ndarray针对的是OpenCV的imread操作Converts a PIL Image or numpy.ndarray (H x W x C) in the range[0, 255] to a torch.FloatTensor of shape (C x H x W) in the range [0.0, 1.0]if the PIL Image belongs to one of the modes (L, LA, P, I, F, RGB, YCbCr, RGBA, CMYK, 1)or if the numpy.ndarray has dtype np.uint8In the other cases, tensors are returned without scaling... note::Because the input image is scaled to [0.0, 1.0], this transformation should not be used whentransforming target image masks. See the references_ for implementing the transforms for image masks... _references: https://github.com/pytorch/vision/tree/main/references/segmentationⅠ通过PIL的Image读取图片类型为PIL使用ToTensor将图片类型转换为tensor并通过add_image上传tensorbord import cv2 as cv from PIL import Image from torch.utils.tensorboard import SummaryWriter from torchvision import transformsimg_path G:/PyCharm/workspace/learning_pytorch/dataset/a/3.jpg# 通过Image打开的图片类型为PIL img Image.open(img_path) print(type(img))#class PIL.JpegImagePlugin.JpegImageFile# # 通过opencv的imread打开的图片类型为numpy.ndarray # img cv.imread(img_path) # print(type(img))#class numpy.ndarray#通过transforms的ToTensor即可转换为Tensor类型 tensor_trans transforms.ToTensor()#创建ToTensor对象 tensor_img tensor_trans(img)#Ctrlp 查看需要传入的参数传入图片 print(type(tensor_img))#class torch.Tensor print(tensor_img.shape)#torch.Size([3, 299, 300]) add_image()要求 ①图片类型为torch.Tensor, numpy.array, or string/blobname ②图片尺寸规格为(3, H, W)若不一样需要通过dataformats参数进行声明 很显然tensor_img满足add_image的基本要求可以直接传入使用 writer SummaryWriter(y_log)writer.add_image(tensor_img,tensor_img)#默认从0开始 writer.close()在Terminal下运行tensorboard --logdiry_log --port2312logdir为打开事件文件的路径port为指定端口打开 通过指定端口2312进行打开tensorboard若不设置port参数默认通过6006端口进行打开。 点击该链接或者复制链接到浏览器打开即可 Ⅱ为啥神经网络中传入的图片数据类型必须是tensor 打开Python Console将上面的代码复制运行 可以看到tensor包含grad梯度等信息也就是tensor数据类型包装了神经网络所需要的一些参数信息 Ⅲ__call__方法的作用 transform.py文件中的ToTensor类下面有一个__call__方法接下来进行探讨下该方法的作用是啥 class Band:def __call__(self, bandname):print(call-bandname)def music_band(self,bandname):print(hello-bandname)band Band() band(beyond)#call-beyond band.music_band(huangjiaju)#hello-huangjiaju由结果可以看出在Band类中若直接对其对象传入参数会使用__call__方法若指定某个方法名称才会使用某方法。其实__call__方法起到默认优先考虑的效果而已。 三、ToPILImage类 看下文档给的使用说明 CtrlP显示方法所需要的参数 Convert a tensor or an ndarray to PIL Image. This transform does not support torchscript. #将tensor、ndarray 转换为PIL类型Converts a torch.*Tensor of shape C x H x W or a numpy ndarray of shapeH x W x C to a PIL Image while preserving the value range.Args:mode (PIL.Image mode_): color space and pixel depth of input data (optional).If mode is None (default) there are some assumptions made about the input data:- If the input has 4 channels, the mode is assumed to be RGBA.- If the input has 3 channels, the mode is assumed to be RGB.- If the input has 2 channels, the mode is assumed to be LA.- If the input has 1 channel, the mode is determined by the data type (i.e int, float,short)... _PIL.Image mode: https://pillow.readthedocs.io/en/latest/handbook/concepts.html#concept-modes通过ToPILImage方法可将tensor、ndarray类型图片转换为PIL类型 from torch.utils.tensorboard import SummaryWriter from PIL import Image import cv2 as cv import numpy as np from torchvision import transformsimg_path G:/PyCharm/workspace/learning_pytorch/dataset/a/3.jpgimg cv.imread(img_path) type(img)#numpy.ndarrayPIL transforms.ToPILImage() PIL_img PIL(img) type(PIL_img)#PIL.Image.ImagePIL_img.show()#展示照片cv.imshow(img,img)#展示照片 cv.waitKey(0) cv.destroyAllWindows()四、Normalize类 看下文档给的使用说明 CtrlP显示方法所需要的参数 Normalize a tensor image with mean and standard deviation. #用均值和标准差归一化张量图像也就是归一化操作This transform does not support PIL Image.Given mean: (mean[1],...,mean[n]) and std: (std[1],..,std[n]) for nchannels, this transform will normalize each channel of the inputtorch.*Tensor i.e.,output[channel] (input[channel] - mean[channel]) / std[channel].. note::This transform acts out of place, i.e., it does not mutate the input tensor.Args:mean (sequence): Sequence of means for each channel.std (sequence): Sequence of standard deviations for each channel.inplace(bool,optional): Bool to make this operation in-place.使用要求必须是tensor类型由文档介绍可得 output[channel] (input[channel] - mean[channel]) / std[channel] from PIL import Image from torch.utils.tensorboard import SummaryWriter import cv2 as cv import numpy as np from torchvision import transformswrite SummaryWriter(y_log)img_path dataset/b/6.jpgimg cv.imread(img_path) print(type(img))#class numpy.ndarray print(img.size)#61375 print(img.shape)#(375, 499, 3)trans_tensor transforms.ToTensor() img_tensor trans_tensor(img) print(type(img_tensor))#class torch.Tensorprint(img_tensor[0][0][0])#tensor(0.5255) trans_normalize transforms.Normalize([0.5, 0.5, 0.5], [0.5, 0.5, 0.5]) img_normalize trans_normalize(img_tensor) print(img_normalize[0][0][0])#tensor(0.0510)#公式output[channel] (input[channel] - mean[channel]) / std[channel] #0.5255-0.5/0.5 0.051print(img_normalize.shape)#torch.Size([3, 375, 499]) #shape符合add_image的要求(C,H,W)可直接传入使用write.add_image(img_normalize,img_normalize)write.close()在Terminal下运行tensorboard --logdiry_log --port2312logdir为打开事件文件的路径port为指定端口打开 通过指定端口2312进行打开tensorboard若不设置port参数默认通过6006端口进行打开。 点击该链接或者复制链接到浏览器打开即可 五、Resize类 看下文档给的使用说明 CtrlP显示方法所需要的参数 Resize the input image to the given size. #将输入图像调整为给定大小也就是对输入图像进行尺寸变换If the image is torch Tensor, it is expectedto have [..., H, W] shape, where ... means an arbitrary number of leading dimensions.. warning::The output image might be different depending on its type: when downsampling, the interpolation of PIL imagesand tensors is slightly different, because PIL applies antialiasing. This may lead to significant differencesin the performance of a network. Therefore, it is preferable to train and serve a model with the same inputtypes. See also below the antialias parameter, which can help making the output of PIL images and tensorscloser.Args:size (sequence or int): Desired output size. If size is a sequence like(h, w), output size will be matched to this. If size is an int,smaller edge of the image will be matched to this number.i.e, if height width, then image will be rescaled to(size * height / width, size). #需要给出要裁剪成的形状(h,w)若只给一个数则默认裁剪成一个正方形.. note::In torchscript mode size as single int is not supported, use a sequence of length 1: [size, ].interpolation (InterpolationMode): Desired interpolation enum defined by:class:torchvision.transforms.InterpolationMode. Default is InterpolationMode.BILINEAR.If input is Tensor, only InterpolationMode.NEAREST, InterpolationMode.BILINEAR andInterpolationMode.BICUBIC are supported.For backward compatibility integer values (e.g. PIL.Image.NEAREST) are still acceptable.max_size (int, optional): The maximum allowed for the longer edge ofthe resized image: if the longer edge of the image is greaterthan max_size after being resized according to size, thenthe image is resized again so that the longer edge is equal tomax_size. As a result, size might be overruled, i.e thesmaller edge may be shorter than size. This is only supportedif size is an int (or a sequence of length 1 in torchscriptmode).antialias (bool, optional): antialias flag. If img is PIL Image, the flag is ignored and anti-aliasis always used. If img is Tensor, the flag is False by default and can be set to True forInterpolationMode.BILINEAR only mode. This can help making the output for PIL images and tensorscloser... warning::There is no autodiff support for antialiasTrue option with input img as Tensor. 输入类型为PIL图片通过Resize转换大小再通过ToTensor转换为tensor类型上传tensorboard from PIL import Image from torch.utils.tensorboard import SummaryWriter import cv2 as cv import numpy as np from torchvision import transformswrite SummaryWriter(y_log)img_path dataset/b/6.jpgimg Image.open(img_path) print(type(img))#class PIL.JpegImagePlugin.JpegImageFile print(img.size)#(499, 375) 原始图片的大小 trans_resize transforms.Resize((300,300)) img_PIL_resize trans_resize(img)#进行裁剪 print(img_PIL_resize)#PIL.Image.Image image modeRGB size300x300 at 0x1FDDC07C9B0 原图像已经变成了(300300)但还是PIL类型#要想上传到tensorboard上必须是tensor、numpy.array类型这里通过ToTensor方法转换为tensor trans_tensor transforms.ToTensor() img_tensor trans_tensor(img_PIL_resize) print(type(img_tensor))#class torch.Tensorwrite.add_image(img_PIL_resize,img_tensor)#默认从0开始write.close()在Terminal下运行tensorboard --logdiry_log --port2312logdir为打开事件文件的路径port为指定端口打开 通过指定端口2312进行打开tensorboard若不设置port参数默认通过6006端口进行打开。 点击该链接或者复制链接到浏览器打开即可 与下面的归一化之后的图像相比大小很明显发生了变化 六、Compose类 看下文档给的使用说明 CtrlP显示方法所需要的参数 Composes several transforms together. This transform does not support torchscript. #组合一些transforms一起使用Please, see the note below.Args:transforms (list of Transform objects): list of transforms to compose.Example: transforms.Compose([ transforms.CenterCrop(10),#先对图片进行一次中心裁剪 transforms.PILToTensor(),#再对图片转换为tensor transforms.ConvertImageDtype(torch.float),#之后再将图像转换为dtype如果需要缩放其值 ])#一个Compose可以实现多次的transforms对图片进行操作.. note::In order to script the transformations, please use torch.nn.Sequential as below. transforms torch.nn.Sequential( transforms.CenterCrop(10), transforms.Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225)), ) scripted_transforms torch.jit.script(transforms)Make sure to use only scriptable transformations, i.e. that work with torch.Tensor, does not requirelambda functions or PIL.Image.说白了就是组合多种transform操作 from PIL import Image from torch.utils.tensorboard import SummaryWriter import cv2 as cv import numpy as np from torchvision import transformswriter SummaryWriter(y_log)img_path dataset/b/6.jpgimg Image.open(img_path) print(type(img))#class PIL.JpegImagePlugin.JpegImageFile print(img.size)#(499, 375) 原始图片的大小 #①剪切尺寸 trans_resize transforms.Resize((300,300)) img_PIL_resize trans_resize(img)#进行裁剪 print(img_PIL_resize)#PIL.Image.Image image modeRGB size300x300 at 0x1FDDC07C9B0 原图像已经变成了(300300)但还是PIL类型#②PIL转Tensor trans_tensor transforms.ToTensor()trans_compose transforms.Compose([trans_resize,trans_tensor]) #Compose参数都是transform对象且第一个输出必须满足第二个输入 #trans_resize为Resize对象最后输出为PIL类型 #trans_tensor为ToTensor对象输入为PIL输出为tensorimg_all trans_compose(img) #因为最后输出为tensor故才可以通过add_image上传至tensorboardwriter.add_image(compose_img,img_all) writer.close()在Terminal下运行tensorboard --logdiry_log --port2312logdir为打开事件文件的路径port为指定端口打开 通过指定端口2312进行打开tensorboard若不设置port参数默认通过6006端口进行打开。 点击该链接或者复制链接到浏览器打开即可该操作其实就是将Resize和ToTensor进行了整合使用而已 八、RandomCrop类 看下文档给的使用说明 CtrlP显示方法所需要的参数 Crop the given image at a random location.If the image is torch Tensor, it is expectedto have [..., H, W] shape, where ... means an arbitrary number of leading dimensions,but if non-constant padding is used, the input is expected to have at most 2 leading dimensionsArgs:size (sequence or int): Desired output size of the crop. If size is anint instead of sequence like (h, w), a square crop (size, size) ismade. If provided a sequence of length 1, it will be interpreted as (size[0], size[0]).padding (int or sequence, optional): Optional padding on each borderof the image. Default is None. If a single int is provided thisis used to pad all borders. If sequence of length 2 is provided this is the paddingon left/right and top/bottom respectively. If a sequence of length 4 is providedthis is the padding for the left, top, right and bottom borders respectively. #需要给出要裁剪成的形状(h,w)若只给一个数则默认裁剪成一个正方形.. note::In torchscript mode padding as single int is not supported, use a sequence oflength 1: [padding, ].pad_if_needed (boolean): It will pad the image if smaller than thedesired size to avoid raising an exception. Since cropping is doneafter padding, the padding seems to be done at a random offset.fill (number or str or tuple): Pixel fill value for constant fill. Default is 0. If a tuple oflength 3, it is used to fill R, G, B channels respectively.This value is only used when the padding_mode is constant.Only number is supported for torch Tensor.Only int or str or tuple value is supported for PIL Image.padding_mode (str): Type of padding. Should be: constant, edge, reflect or symmetric.Default is constant.- constant: pads with a constant value, this value is specified with fill- edge: pads with the last value at the edge of the image.If input a 5D torch Tensor, the last 3 dimensions will be padded instead of the last 2- reflect: pads with reflection of image without repeating the last value on the edge.For example, padding [1, 2, 3, 4] with 2 elements on both sides in reflect modewill result in [3, 2, 1, 2, 3, 4, 3, 2]- symmetric: pads with reflection of image repeating the last value on the edge.For example, padding [1, 2, 3, 4] with 2 elements on both sides in symmetric modewill result in [2, 1, 1, 2, 3, 4, 4, 3] 说白了就是随机对图片进行裁剪 from PIL import Image from torch.utils.tensorboard import SummaryWriter import cv2 as cv import numpy as np from torchvision import transformswriter SummaryWriter(y_log)img_path dataset/b/6.jpgimg Image.open(img_path) print(type(img))#class PIL.JpegImagePlugin.JpegImageFile print(img.size)#(499, 375) 原始图片的大小 #①随机剪切尺寸 trans_random transforms.RandomCrop((200,250))#(h,w) img_PIL_random trans_random(img)#随机进行裁剪 print(img_PIL_random)#PIL.Image.Image image modeRGB size250,200 at 0x1FDDC07C9B0 #PIL输出为(w,h)即原图像已经变成了(h,w)(200,250)但还是PIL类型#②PIL转Tensor trans_tensor transforms.ToTensor()trans_compose transforms.Compose([trans_random,trans_tensor]) #Compose参数都是transform对象且第一个输出必须满足第二个输入 #trans_resize为Resize对象最后输出为PIL类型 #trans_tensor为ToTensor对象输入为PIL输出为tensorfor i in range(10):img_randomcrop trans_compose(img)# 因为最后输出为tensor故才可以通过add_image上传至tensorboardwriter.add_image(img_randomcrop,img_randomcrop,i)writer.close()在Terminal下运行tensorboard --logdiry_log --port2312logdir为打开事件文件的路径port为指定端口打开 通过指定端口2312进行打开tensorboard若不设置port参数默认通过6006端口进行打开。 点击该链接或者复制链接到浏览器打开即可 七、CenterCrop类 看下文档给的使用说明 CtrlP显示方法所需要的参数 Crops the given image at the center. #对图像进行中心裁剪If the image is torch Tensor, it is expectedto have [..., H, W] shape, where ... means an arbitrary number of leading dimensions.If image size is smaller than output size along any edge, image is padded with 0 and then center cropped.Args:size (sequence or int): Desired output size of the crop. If size is anint instead of sequence like (h, w), a square crop (size, size) ismade. If provided a sequence of length 1, it will be interpreted as (size[0], size[0]).说白了就是对图像进行中心裁剪 from PIL import Image from torch.utils.tensorboard import SummaryWriter import cv2 as cv import numpy as np from torchvision import transformswriter SummaryWriter(y_log)img_path dataset/b/6.jpgimg Image.open(img_path) print(type(img))#class PIL.JpegImagePlugin.JpegImageFile print(img.size)#(499, 375) 原始图片的大小 #①中间剪切尺寸 trans_center transforms.CenterCrop((200,250))#(h,w) img_PIL_center trans_center(img)#随机进行裁剪 print(img_PIL_center)#PIL.Image.Image image modeRGB size250,200 at 0x1FDDC07C9B0 #PIL输出为(w,h)即原图像已经变成了(h,w)(200,250)但还是PIL类型#②PIL转Tensor trans_tensor transforms.ToTensor()trans_compose transforms.Compose([trans_center,trans_tensor]) #Compose参数都是transform对象且第一个输出必须满足第二个输入 #trans_resize为Resize对象最后输出为PIL类型 #trans_tensor为ToTensor对象输入为PIL输出为tensorimg_centercrop trans_compose(img)writer.add_image(img_centercrop,img_centercrop) writer.close()在Terminal下运行tensorboard --logdiry_log --port2312logdir为打开事件文件的路径port为指定端口打开 通过指定端口2312进行打开tensorboard若不设置port参数默认通过6006端口进行打开。 点击该链接或者复制链接到浏览器打开即可
http://www.huolong8.cn/news/458167/

相关文章:

  • 做网站有意思吗?建设中专网站首页
  • 北京南站到北京站坐地铁几号线网络诚信 网站应怎么做
  • 给手机开发网站外贸是做什么的很赚钱吗
  • 简述创建一个网站的过程网站建站的费用
  • 做文献综述的文章用什么网站江苏省建设网站首页
  • 海南通信建设有限公司官方网站深圳做二类学分的网站
  • 如何自己建站网站制作泉州刺桐古建筑公司网站
  • 建设一个网站需要那些技术wordpress标签不解析
  • 网站如何快速备案sever2012 网站建设
  • 凡科建设网站别人能进去么权威发布的最新通告
  • 做网站很赚钱公司全网推广
  • 门头沟区专业网站制作网站建设彩神app官方网站开发
  • 黄岩网站制作天水头条最新消息今天
  • 广州市官网网站建设怎么样大同网站设计
  • 长治网站建设收费多少做网站需要的图片
  • 寮步网站建设外贸网站建设高端的
  • 快速搭建网站的好处西安seo外包行者seo
  • VR网站建设价格wordpress小程序怎么发布文章
  • 网站建设外文文献翻译大连seo推广外包
  • 手机做简单的网站维护网站要做哪些工作
  • 怎样做国外网站wordpress端点设错自已进不去
  • 建设银行网站打印账单东莞网站建设dgjwz
  • 网站备案好麻烦用DW做的网站生成链接
  • 做网站推广每天加班谷歌搜索引擎入口2022
  • 广州建设营销型网站浙江建设职业技术学院招生网站
  • 北京网站优化推广方案网站开发安全
  • 二手房网站制作教程怎么实现网站建设报价方案
  • 大连网站开发招聘百度推广一年收费标准
  • 网站开发前景怎么样怎么样检查网站有没有做全站301
  • 建设教育协会官方网站吉安网站建设jajjjc