当前位置:   article > 正文

深度学习bug笔记_attributeerror: 'float' object has no attribute 'r

attributeerror: 'float' object has no attribute 'round

目录

1、WARNING: Ignoring invalid distribution -ip

2、ValueError: check_hostname requires server_hostname

3、ValueError:only one element tensors can be converted to Python scalars

4、TypeError: ‘int‘ object is not iterable

5、pandas的SettingWithCopyWarning警告

6、AttributeError: 'float' object has no attribute 'round'

7、ValueError: cannot set a row with mismatched columns

8、输出的时候多了一层中括号怎么办


1、WARNING: Ignoring invalid distribution -ip

删除对应目录(C:\Users\用户名\anaconda3\envs\yolov5\Lib\site-packages)下的所有前缀为~的文件夹

原因是,这些东西未下载完全,被终端下载过

2、ValueError: check_hostname requires server_hostname

主要出现在conda的pip在线安装过程中出现的错误

关掉VPN后问题解决

3、ValueError:only one element tensors can be converted to Python scalars

原因:要转换的list里面的元素包含多维的tensor

list,tensor,array之间的转换很复杂,list是python自带的数据结构,Tensor是pytorch深度学习框架带的数据格式,array则是numpy带的数据格式,三种之间不可以直接使用,需要转换后才可以使用。

一般情况下的 list 转 tensor :

tensor=torch.tensor(list)
但是要转换的list里面的元素包含多维的tensor,应该使用
val= torch.tensor([item.cpu().detach().numpy() for item in val]).cuda()

首先,这个数据是list,但是不知道这个list包含了几个维度的tensor,所以需要(for in)结构遍历

然后, gpu上的 tensor 不能直接转为numpy; 须要先在 cpu 上完成操做,再回到 gpu 上。

4、TypeError: ‘int‘ object is not iterable

int类型不可以遍历,这种可以操作

  1. for i in range(5):
  2.    print(i)

这种情况则会出现bug

  1. station_names = ['Beijing', 'Shanghai', 'Guangzhou', 'Shenzhen']
  2. for num in len(station_names):
  3. station_uppercase = station_names[num].upper()
  4. print(station_uppercase)

出现bug:TypeError: ‘int’ object is not iterable

解决方法:

  1. station_names = ['Beijing', 'Shanghai', 'Guangzhou', 'Shenzhen']
  2. for num in range(len(station_names)):
  3. station_uppercase = station_names[num].upper()
  4. print(station_uppercase)

就可以了

5、pandas的SettingWithCopyWarning警告

df_data[df_data.tmpf < 100].valid= '2016/7/1 0:00''
运行

上述操作,是将dataframe的某一valid列全部赋值成一个值,则会出现该警告

6、AttributeError: 'float' object has no attribute 'round'

  1. import time
  2. time_start = time.time()  # 记录开始时间
  3. # function()   执行的程序
  4. time_end = time.time()  # 记录结束时间
  5. time_sum = (time_end - time_start).round(2)  # 计算的时间差为程序的执行时间,单位为秒/s
  6. print(time_sum)

time_sum = (time_end - time_start).round(2)改为

time_sum = round( (time_end - time_start), 2 )

7、ValueError: cannot set a row with mismatched columns

将两个DataFrame拼接的时候,两个DataFrame的格式必须完全相同,如每个列名,列名的个数,以及每个列名对应的值得个数也要相同

8、输出的时候多了一层中括号怎么办

将append()改为extend()

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/905091
推荐阅读
相关标签
  

闽ICP备14008679号