python 与 pytorch
小帽哥aicv
这个作者很懒,什么都没留下…
展开
-
SyntaxError: Non-UTF-8 code starting with ‘\xb4‘ in file x3.py on line 10, but no encoding declared;
表示设置编码格式为utf8即可解决。原创 2023-03-15 17:17:55 · 721 阅读 · 0 评论 -
c1: fatal error C1083: 无法打开源文件: “pycocotools/_mask.c”: No such file or directoryerror: Setup script
c1: fatal error C1083: 无法打开源文件: “pycocotools/_mask.c”: No such file or directory。原创 2023-03-15 09:58:16 · 731 阅读 · 0 评论 -
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C head
原因:numpy 版本低原创 2022-07-05 14:24:01 · 1198 阅读 · 0 评论 -
ERROR: No matching distribution found for git
ERROR: No matching distribution found for git原创 2022-06-07 09:51:08 · 5330 阅读 · 0 评论 -
tensorboard命令
tensorboard --logdir=E:/py-pro/liu-runda-yolov3-train-master/train2/train/log_dir/ --host=127.0.0.1原创 2022-05-19 10:54:59 · 468 阅读 · 0 评论 -
To search for alternate channels that may provide the conda package you‘re looking for, navigate
一、描述:To search for alternate channels that may provide the conda package you’re looking for, navigate to https://anaconda.organd use the search bar at the top of the page.二、解决方法:在anaconda prompt(anaconda3)下输入以下命令:conda config --add channels cond..原创 2022-04-21 22:55:01 · 12911 阅读 · 0 评论 -
[W IndexingUtils.h:25] Warning: indexing with dtype torch.uint8 is now deprecated, please use a dtyp
Pytorch 遇到[W IndexingUtils.h:25] Warning: indexing with dtype torch. uint8 is now deprecated警告信息*_tanpengjie的博客-CSDN博客原创 2022-02-28 22:58:11 · 662 阅读 · 0 评论 -
pytorch中模型的保存与加载:torch.save(),torch.load()
pytorch保存模型与加载:模型的保存torch.save(net,PATH)#保存模型的整个网络,包括网络的整个结构和参数torch.save(net.state_dict,PATH)#只保存网络中的参数模型的加载分别对应上边的加载方法。model_dict=torch.load(PATH)model_dict=net.load_state_dict(torch.load(PATH))...原创 2022-01-05 09:35:12 · 1582 阅读 · 0 评论 -
OSError: [WinError 1455] 页面文件太小,无法完成操作。
num_workers 设置成0原创 2021-12-03 10:52:09 · 192 阅读 · 0 评论 -
Python3 super().__init__()
super().__init__() 的含义是 调用父类的__init__然后给子类创建了self.x属性,而不是调用父类的属性。原创 2021-12-02 10:57:25 · 311 阅读 · 0 评论 -
gym 的 emv.unwrapped 的含义
创建环境:env = gym.make('CartPole-v0')返回的这个env其实并非CartPole类本身,而是一个经过包装的环境:据说gym的多数环境都用TimeLimit(源码)包装了,以限制Epoch,就是step的次数限制,比如限定为200次。所以小车保持平衡200步后,就会失败。用env.unwrapped可以得到原始的类,原始类想step多久就多久,不会200步后失败:...转载 2021-10-13 15:54:36 · 522 阅读 · 0 评论 -
openAI gym 的环境
from gym import envsprint(envs.registry.all())上述代码可查看注册的环境。下面列出gym包含的环境EnvSpec(Acrobot-v1),EnvSpec(AirRaid-ram-v0),EnvSpec(AirRaid-ram-v4),EnvSpec(AirRaid-ramDeterministic-v0),EnvSpec(AirRaid-ramDeterministic-v4),EnvSpec(AirRaid-ramNoFrameskip-原创 2021-10-12 13:39:08 · 360 阅读 · 0 评论 -
ImportError: sys.meta_path is None, Python is likely shutting down
我的平台是 win10 + python3.6 + pytorch1.7.0在最后添加env.close() ,关闭环境原创 2021-10-12 13:25:06 · 244 阅读 · 0 评论 -
gym.error.DependencyNotInstalled: Found neither the ffmpeg nor avconv executables. On OS X, you can
问题描述 :gym.error.DependencyNotInstalled: Found neither the ffmpeg nor avconv executables. On OS X, you can install ffmpeg via `brew install ffmpeg`. On most Ubuntu variants, `sudo apt-get install ffmpeg` should do it. On Ubuntu 14.04, however, you'll need原创 2021-10-12 08:53:42 · 361 阅读 · 0 评论 -
Exception: ROM is missing for pong, see https://github.com/openai/atari-py#roms for instructions
我的环境是:win10 + python3.6 + pytorch1.7.0gym 版本是 0.13.0安装pip install atari-py==0.2.5 解决原创 2021-10-11 18:22:21 · 411 阅读 · 0 评论 -
gym.error.DependencyNotInstalled: No module named ‘atari_py‘. (HINT: you can install Atari dependenc
我的环境是:win10 + python3.6 + pytorch1.7.0gym 版本是 0.13.0安装pip install atari-py 解决原创 2021-10-11 18:21:32 · 580 阅读 · 0 评论 -
numpy 变量 交换ndarray 的维度
img = np.transpose(img, (1, 2, 0))原img是1*28*28(c*h*w) 的手写字体数据集的图像,将图像的维度转换为28*28*1(h*w*c)原创 2021-10-03 10:52:39 · 806 阅读 · 0 评论 -
RuntimeError: stack expects each tensor to be equal size, but got [1, 5] at entry 0 and [3, 5] at en
https://blog.csdn.net/yuxiang8546/article/details/118761999在 dataset 类里 添加def yolo_dataset_collate(batch): images = [] bboxes = [] for img, box in batch: images.append(img) bboxes.append(box) images = np.array(images)原创 2021-07-15 16:22:20 · 8177 阅读 · 4 评论 -
读图 to tensor
img = torch.from_numpy( cv2.imread('C:/Users/gaojo/Desktop/22.png') ).float()img = torch.unsqueeze(img,0)img = img.permute(0,3,1,2)原创 2021-07-14 15:33:28 · 154 阅读 · 0 评论 -
from import
from 文件夹.文件名 import 类名或函数名原创 2021-07-14 15:31:43 · 83 阅读 · 0 评论 -
mat1 and mat2 shapes cannot be multiplied (3584x7 and 512x4096)
改为:原创 2021-07-14 15:26:43 · 7718 阅读 · 2 评论 -
RuntimeError: expected scalar type Byte but found Float
img = torch.from_numpy( cv2.imread('C:/Users/gaojo/Desktop/22.png') )改为 :img = torch.from_numpy( cv2.imread('C:/Users/gaojo/Desktop/22.png') ).float()原创 2021-07-14 14:08:29 · 2971 阅读 · 1 评论 -
Pytorch Tensor维度调换
permute如果四个维度表示上节的[batch,channel,h,w] ,如果想把channel放到最后去,形成[batch,h,w,channel],那么如果使用前面的维度交换,至少要交换两次(先13交换再12交换)。而使用permute可以直接指定维度新的所处位置,更加方便。示例代码:a = torch.rand(4, 3, 6, 7)print(a.permute(0, 2, 3, 1).shape)输出结果:torch.Size([4, 6, 7, 3])—————————原创 2021-07-14 14:02:19 · 1287 阅读 · 0 评论 -
Main主文件模板
import torch.optim as optimfrom LeNet5 import *from train import *from data_loader import *from test import *import torchfrom alexnet import *from minstSet import *from .原创 2020-08-23 21:01:55 · 186 阅读 · 0 评论 -
读Mnist 数据集
import numpy as npimport structimport matplotlib.pyplot as plt# 训练集文件train_images_idx3_ubyte_file = 'D:\\QQ消息记录\\1694233142\\FileRecv\\mnist\\mnist\\train-images.idx3-ubyte'# 训练集标签文件train_labels_idx1_ubyte_file = 'D:\\QQ消息记录\\1694233142\\FileRecv\\.原创 2020-08-23 20:59:38 · 256 阅读 · 0 评论 -
Dataloader 加载训练数据
import torchfrom torchvision import datasets, transformsdef data_loader(): train_data = torch.utils.data.DataLoader( # 加载训练数据 datasets.MNIST('../data', train=True, download=True, transform=transforms.Compose([ .原创 2020-08-23 20:56:15 · 464 阅读 · 0 评论 -
test 测试网络模板
from torch.autograd import Variableimport torch.nn.functional as Fdef test(model,test_loader,device): model.eval() # 设置为test模式 test_loss = 0 # 初始化测试损失值为0 correct = 0 # 初始化预测正确的数据个数为0 for data, target in test_loader: data = d.原创 2020-08-23 20:54:23 · 496 阅读 · 0 评论 -
train 训练网络模板
import torch.nn.functional as Ffrom torch.autograd import Variableimport numpy as npimport cv2from PIL import Imagefrom LeNet5 import *def train(i,model,train_Set,optimizer,device): model.train() for batch_idx,(data,target) in enumerate(t.原创 2020-08-23 20:53:33 · 708 阅读 · 1 评论 -
AlexNet
import torch.nn as nnclass alexnet(nn.Module): def __init__(self): super(alexnet,self).__init__() self.conv1 = nn.Sequential( nn.Conv2d(1,96,kernel_size=3,stride=1,padding=1), nn.ReLU(inplace=True) ,nn.MaxPool2d(kernel_size=3,stride.原创 2020-08-23 20:52:08 · 71 阅读 · 0 评论 -
LeNet5
import torch.nn as nnclass LeNet5(nn.Module): def __init__(self): super(LeNet5,self).__init__() self.conv1 = nn.Sequential( nn.Conv2d(1,6,5,1,2) , nn.ReLU() , nn.MaxPool2d(2,2) ) self.conv2 = nn.Sequential( nn.Conv2d(6,.原创 2020-08-23 20:49:07 · 166 阅读 · 0 评论