AttributeError: ‘list‘ object has no attribute ‘endswich‘

今天出现这个错误后,在谷歌和百度上都查不到,有些人是打成了endwith,或者是startwith。

所以我抱着怀疑的态度,去翻找了一下我自己写的代码,发现我写错成了endswich。

其实正确拼写是endswith啊!!!

# 数据集主目录
DATA_ROOT = 'D:\BaiduNetdiskDownload\pycv-learning\data\spot_data_cls'

# 训练集验证集划分比例,8:2
train_ratio = 0.8
num_epochs = 5
learning_rate = 1e-3
resized_img_shape = (224, 224, 3)
batch_size = 16

# 创建path对象
DATA_ROOT_PATH = Path(DATA_ROOT)

# 获取所有类别图片对应的目录
ClASS_list = [str(p) for p in DATA_ROOT_PATH.iterdir() if p.is_dir() 
              and not str(p).endswith('Set') 
              and not str(p).startswith('.')]
dict_num2name = {}  # 数据集标签序号to类别名称的转换字典
dict_name2num = {}  # 数据集类别名称to标签序号的转换字典
sep_class_paths = {}  # 获取数据集下的各个类别的图片路径
train_whole_paths,train_whole_labels,val_whole_paths,val_whole_labels = [],[],[],[]

for i,path in enumerate(ClASS_list):
    dict_num2name[i] = Path(path).name  # {0: 'copper', 1: 'edge', 2: 'normal', 3: 'overlap', 4: 'splash', 5: 'twist'}
    dict_name2num[Path(path).name] = i  # {'copper': 0, 'edge': 1, 'normal': 2, 'overlap': 3, 'splash': 4, 'twist': 5}
    sep_class_paths[Path(path).name] = list(map(lambda x : str(x), Path(path).iterdir()))
    
    np.random.shuffle(sep_class_paths[Path(path).name])
    train_whole_paths.extend(sep_class_paths[Path(path).name][:int(train_ratio*len(sep_class_paths[Path(path).name]))])
    val_whole_paths.extend(sep_class_paths[Path(path).name][int(train_ratio*len(sep_class_paths[Path(path).name])):])

# 对全部的训练集、验证集图片路径进行打乱
np.random.shuffle(train_whole_paths)
np.random.shuffle(val_whole_paths)

# 根据图片文件路径的上一级路径的名称来确定label
for path in train_whole_paths:
    serial_number = dict_name2num[os.path.basename(os.path.abspath(path + '/../'))]
    train_whole_labels.append(serial_number)
for path in val_whole_paths:
    serial_number = dict_name2num[os.path.basename(os.path.abspath(path + '/../'))]
    val_whole_labels.append(serial_number)

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Git 2.33 Release Notes ====================== Updates since Git 2.32 ---------------------- UI, Workflows & Features * "git send-email" learned the "--sendmail-cmd" command line option and the "sendemail.sendmailCmd" configuration variable, which is a more sensible approach than the current way of repurposing the "smtp-server" that is meant to name the server to instead name the command to talk to the server. * The userdiff pattern for C# learned the token "record". * "git rev-list" learns to omit the "commit " header lines from the output with the `--no-commit-header` option. * "git worktree add --lock" learned to record why the worktree is locked with a custom message. Performance, Internal Implementation, Development Support etc. * The code to handle the "--format" option in "for-each-ref" and friends made too many string comparisons on %(atom)s used in the format string, which has been corrected by converting them into enum when the format string is parsed. * Use the hashfile API in the codepath that writes the index file to reduce code duplication. * Repeated rename detections in a sequence of mergy operations have been optimized out for the 'ort' merge strategy. * Preliminary clean-up of tests before the main reftable changes hits the codebase. * The backend for "diff -G/-S" has been updated to use pcre2 engine when available. * Use ".DELETE_ON_ERROR" pseudo target to simplify our Makefile. * Code cleanup around struct_type_init() functions. * "git send-email" optimization. * GitHub Actions / CI update. (merge 0dc787a9f2 js/ci-windows-update later to maint). * Object accesses in repositories with many alternate object store have been optimized. * "git log" has been optimized not to waste cycles to load ref decoration data that may not be needed. * Many "printf"-like helper functions we have have been annotated with __attribute__() to catch placeholder/parameter

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值