
代码问题
taxuewuhenxiaoer
留给自己的笔记
展开
-
scp 上传文件 permission denied
现在是把本地文件上传到服务器上,遇到permission denied 的情况。然后去服务器上,找到这个目录/data1/ ,使用root权限 输入。如果 permission denied。这样,应该就可以上传了。原创 2024-01-27 13:10:20 · 1003 阅读 · 1 评论 -
linux查找文件
linux查找文件。原创 2024-01-24 20:19:40 · 398 阅读 · 0 评论 -
torch.matmul()
torch.matmul()原创 2022-11-17 20:30:45 · 258 阅读 · 0 评论 -
ModuleNotFoundError: No module named ‘numba‘
ModuleNotFoundError: No module named ‘numba’pip install numba原创 2022-11-09 16:05:35 · 1350 阅读 · 0 评论 -
RuntimeError: 1only batches of spatial targets supported (3D tensors) but got targets of size: : [1]
这个原因主要是因为,有个tensor 是三维的,但实际上代码需要是二维的tensor (我的代码遇到的问题是这样,网上众说纷纭,但没看到我需要的答案)首先找到代码报错那行,然后,看看哪个是三维的,需要转换成二维。原创 2022-11-09 10:49:02 · 4288 阅读 · 0 评论 -
RuntimeError: invalid argument 4: Index tensor must have same size as output tensor apart from the s
RuntimeError: invalid argument 4: Index tensor must have same size as output tensor apart from the specified dimension at /opt/conda/conda-bld/pytorch_1587428398394/work/aten/src/THC/generic/THCTensorScatterGather.cu:328坑,找了一圈,发现自己的代码是环境问题...原创 2022-04-29 20:33:48 · 690 阅读 · 0 评论 -
vscode调试出错 FileNotFoundError: [Errno 2] No such file or directory: ‘/media/data3/a/tools/train.py
FileNotFoundError: [Errno 2] No such file or directory: '/media/data3/a/tools/train.pyvscode调试出错,明明有这个路径,但报错,原因是因为launch.json里面路径多个空格类似于这种"program": "/media/data3/a/tools/train.py ", # 在.py 后面多了一个空格...原创 2022-02-15 10:34:10 · 1661 阅读 · 1 评论 -
RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn
RuntimeError: element 0 of tensors does not require grad and does not have a grad_fn找到那个tensor,假设为x, 然后后面加上x = x.clone().detach().requires_grad_(True)或者x = torch.tensor(x,requires_grad=True)原创 2022-01-28 20:36:51 · 2646 阅读 · 0 评论 -
-bash: ./tools/dist_train.sh: Permission denied
-bash: ./tools/dist_train.sh: Permission denied只需要:chmod 777 ./tools/dist_train.sh原创 2021-12-12 16:27:18 · 5731 阅读 · 0 评论 -
RuntimeError: CUDA error: CUBLAS_STATUS_INVALID_VALUE when calling `cublasSgemm( handle, opa, opb, m
RuntimeError: CUDA error: CUBLAS_STATUS_INVALID_VALUE when calling cublasSgemm( handle, opa, opb, m, n, k, &alpha, a, lda, b, ldb, &beta, c, ldc)错误的原因是nn.Linear() 维度错了原创 2021-10-08 11:26:33 · 11713 阅读 · 13 评论 -
DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warnin
DeprecationWarning: np.float is a deprecated alias for the builtin float. To silence this warning, use float by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use np.float64 here.把错误那行代码里面的np原创 2021-10-07 11:01:49 · 10416 阅读 · 3 评论 -
vscode里面launch.json 写法,供参考
vscode里面launch.json 写法,供参考 (2021-09-30){ // 使用 IntelliSense 了解相关属性。 // 悬停以查看现有属性的描述。 // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "随便自己起", "type": "python", "request": "l原创 2021-09-30 17:03:19 · 2140 阅读 · 0 评论 -
vscode调试的时候左下角没有选择虚拟环境的标志
vscode调试的时候左下角没有选择虚拟环境的标志那就加载一下 Pylance 和 Python原创 2021-09-28 16:37:17 · 3832 阅读 · 4 评论 -
RuntimeError: CUDA error: device kernel image is invalid
RuntimeError: CUDA error: device kernel image is invalid降低pythorch 版本conda install pytorch=1.2原创 2021-09-17 21:40:18 · 3907 阅读 · 0 评论 -
vscode could not establish connection to “***”
vscode一直连不上服务器,是 could not establish connection to “***”之前一直用这个服务器,可能记住了以前的账号,目前需要删掉以前的信息,除了在vscode上面的config文件删掉内容外,还是连不上,那么就去 本地找 .ssh 文件,直接搜就可以找到这个文件,然后把之前建的账号全部删掉,就可以了...原创 2021-09-17 16:42:29 · 577 阅读 · 0 评论 -
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! (when checking arugment for argument mat1 in method wrapper_addmm)首先,找到报错的那行代码,然后,在后面加上**.cuda()**例如test_class_word_embedding = data[‘test_class原创 2021-08-19 01:31:18 · 3261 阅读 · 1 评论 -
把list和str进行合并
aim_class_names 是一个list:里面有[‘giving_or_receiving_award’, ‘reading_book’, ‘hopscotch’, ‘breakdancing’, 'massaging_b’]aim_query_name 是一个str,里面有 ['massaging_b’]#分别赋值给a,b,不想破坏原有的a = {}b = {}a = aim_class_namesb = aim_query_nameb1 = b.split() # 把 str变成l原创 2021-08-18 17:47:41 · 322 阅读 · 0 评论 -
TypeError: can‘t convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to
TypeError: can’t convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.a1 = a1.data.cpu().numpy()原创 2021-08-17 13:21:29 · 993 阅读 · 0 评论 -
取数组里面前两个最大值
取数组里面前两个最大值,然后,通过做一个比值,用于后面的操作 l = distance_cosine # distance_cosine,这是一个数组,我想取里面的前两个值,因为不想破坏原来的distance_cosine,做了个赋值操作 predicted_y = np.argsort(-distance_cosine) # 对 distance_cosine 的值由大到小排序,之后,得到对应的索引 max = predicted_原创 2021-08-17 12:36:08 · 730 阅读 · 0 评论 -
取出array里面的第几个数
比如说L= [3,2,4,8]取出array里面的第1个数num_1 = L[:,0]那么num_1 是 3取出array里面的第2个数num_1 = L[:,1]那么num_1 是 2原创 2021-08-17 12:14:16 · 586 阅读 · 0 评论 -
not enough values to unpack (expected 2, got 1)
not enough values to unpack (expected 2, got 1)啊一个小问题,我搞了好久,当时以为其他地方出问题,万万没想到啊predicted_y,loss = self.myClassifier.predict(data_result,a1)调用这个函数其实出来就一个值,算了。。。我一直以为是data_result 格式不对。。。无语==...原创 2021-08-17 03:07:28 · 304 阅读 · 0 评论 -
‘numpy.ndarray‘ object has no attribute ‘append‘
’numpy.ndarray’ object has no attribute 'append’头上加个fusion_fea = []在后面的for循环中:加入 fusion_fea.append(fusion_fea_0)原创 2021-08-16 22:09:26 · 2679 阅读 · 0 评论 -
can‘t convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory
can’t convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first改写成这种形式 fusion_fea_0 = fusion_fea_0.data.cpu().numpy()原创 2021-08-16 22:07:19 · 1993 阅读 · 1 评论 -
RuntimeError: Function MmBackward returned an invalid gradient at index 0 - got [5, 2048] but expect
RuntimeError: Function MmBackward returned an invalid gradient at index 0 - got [5, 2048] but expected shape compatible with [5, 4096]这个问题是在定义的时候出错比如代码self.fc = nn.Linear(2048, 2048) 这是错误的改成 self.fc = nn.Linear(4096, 2048)...原创 2021-08-12 01:45:43 · 5604 阅读 · 0 评论 -
TypeError: ‘tuple‘ object is not callable
TypeError: ‘tuple’ object is not callable报了一堆错误,然后,也没定位好哪句错了,因为我只加了一行代码,就报这个错误,那么只从这一行下手就好,一直没看出来,今天在次翻阅下,一看,原来是这行代码多了一个逗号,也不知道有没有和我同样问题的,先记录下吧...原创 2021-08-09 17:16:04 · 476 阅读 · 1 评论 -
AttributeError: module ‘torch.nn‘ has no attribute ‘GELU‘
AttributeError: module ‘torch.nn’ has no attribute 'GELU’升级pytorch版本去pytorch官网找那行代码源代码 是 self.af1 = nn.GELU() #original 变成 **self.af1 = nn.ReLU(inplace=True)** #me原创 2021-07-30 11:09:23 · 6879 阅读 · 4 评论 -
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu and
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cpu and cuda:0! (when checking arugment for argument mat1 in method wrapper_addmm)说至少有两个设备,cup 和 cuda 0其实就加了一个MLP,然后想测一下,结果就报这个错误方法是:self.mlp1 = MLP(2048)在这个原创 2021-07-25 17:07:37 · 3043 阅读 · 0 评论 -
EOFError: marshal data too short
EOFError: marshal data too short报了一堆错误,删掉原代码的_pycache_这个文件夹就可以了原创 2021-07-25 11:17:10 · 1230 阅读 · 0 评论 -
RuntimeError: batch1 dim 2 must match batch2 dim 1
RuntimeError: batch1 dim 2 must match batch2 dim 1这个问题就是两个特征的维度要匹配比如,这个代码A = torch.bmm(exemplar_corr, query_flat)exemplar_corr 特征大小为[96, 49, 1024])query_flat 特征大小为 [96, 2048, 49]那这样的话,就会报上面的错误,1024 和2048 无法相乘...原创 2021-07-22 16:51:59 · 3712 阅读 · 0 评论 -
安装tensorflow
pip3 install tensorflow-gpu原创 2021-06-25 21:02:00 · 104 阅读 · 0 评论 -
查看服务器上硬盘使用情况
查看服务器上硬盘使用情况df -h原创 2021-06-21 21:05:56 · 538 阅读 · 0 评论 -
RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is Fal
RuntimeError: Attempting to deserialize object on a CUDA device but torch.cuda.is_available() is False. If you are running on a CPU-only machine, please use torch.load with map_location=‘cpu’ to map your storages to the CPU.代码出错的原因是因为,我的GPU没有这个7,而我代码里这么写原创 2021-06-20 20:43:05 · 328 阅读 · 0 评论 -
固定模型参数
固定backbone模型参数,留个底if cfg.fewshot_training:for key, value in model.named_parameters():if ‘backbone’ in key:value.requires_grad = False原创 2021-05-28 21:31:19 · 564 阅读 · 0 评论 -
ModuleNotFoundError: No module named ‘cv2‘
pip install opencv-python原创 2021-05-09 13:33:31 · 198 阅读 · 0 评论 -
ImportError: attempted relative import with no known parent package
ImportError: attempted relative import with no known parent package这种错误就把加载的包,把相对路径全部改成绝对路径原创 2021-03-05 21:15:28 · 268 阅读 · 0 评论 -
-bash:........ Permission denied
-bash:… Permission deniedchmod 777 xx.sh原创 2021-03-01 13:18:36 · 4553 阅读 · 0 评论 -
linux 给文件改名字
linux 给文件改名字mv 原先的名字 你想要的名字比如 mv resnet.py resnet_original.py这样就把resnet.py 改为了 resnet_original.py原创 2021-02-24 10:55:03 · 1873 阅读 · 1 评论 -
RuntimeError: NCCL error in: /pytorch/torch/lib/c10d/ProcessGroupNCCL.cpp:784, unhandled system erro
刚刚调程序报了一堆错误,其实挺简单的,看着网上的回复都不符合我这个代码错误的需求,其实就是你写的.sh文件里面,用多个gpu代码,出现了中文符号原创 2021-02-22 11:28:25 · 20763 阅读 · 4 评论 -
SyntaxError: invalid syntax
每每遇到,都要去查一次,其实很简单def __init__(self, num_classes, in_channels, dropout_ratio=0.4, init_std=0.01, sigma=0.01, bias=True, **kwargs):定义这些变原创 2021-02-15 21:35:16 · 345 阅读 · 0 评论 -
ModuleNotFoundError: No module named ‘gensim‘/ ‘sklearn‘/‘nltk‘
原来都是包ModuleNotFoundError: No module named ‘gensim’安装:pip install gensimModuleNotFoundError: No module named ‘sklearn’安装:pip install scikit-learnModuleNotFoundError: No module named ‘nltk’安装:pip install nltk原创 2021-02-14 14:09:37 · 1074 阅读 · 0 评论