ssd-tensorflow报错 labels.append(int(VOC_LABELS[label][0])) KeyError:‘liqin’ 问题解决

参考文章:https://blog.csdn.net/qigeyonghuming_1/article/details/89205690
找到datasets文件夹下的pascalvoc_to_tfrecords.py文件。
找到103行

labels.append(1)#int(VOC_LABELS[label][0])label对应的类别编号,此处直接使用1.没什么特殊意义

解决!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
优化以下代码,# 构建特征矩阵和标签向量 X = [] y = data['Rating'] for index, row in data.iterrows(): features = [] # 添加运行时长区间评分 if pd.notna(row['RunTime']): category1 = pd.cut([row['RunTime']], bins=bins1, labels=labels1)[0] if category1 in avg_runtime_ratings: features.append(avg_runtime_ratings[category1]) else: features.append(0) else: features.append(0) # 添加年份区间评分 if pd.notna(row['year']): category2 = pd.cut([row['year']], bins=bins2, labels=labels2)[0] if category2 in avg_year_ratings: features.append(avg_year_ratings[category2]) else: features.append(0) else: features.append(0) # 添加导演评分 if row.Director in avg_director_ratings: features.append(avg_director_ratings[row.Director]) else: features.append(0) # 添加编剧评分 if row.Writer in avg_writer_ratings: features.append(avg_writer_ratings[row.Writer]) else: features.append(0) # 添加主演评分 casts = row.TopTwoCasts.split(',') if len(casts) == 1: cast = casts[0] if cast in avg_casts_ratings: features.append(avg_casts_ratings[cast]) else: features.append(0) features.extend([0, 0]) else: cast_1, cast_2 = casts if cast_1 in avg_casts_ratings: features.append(avg_casts_ratings[cast_1] * 0.6) else: features.append(0) if cast_2 in avg_casts_ratings: features.append(avg_casts_ratings[cast_2] * 0.4) else: features.append(0) # 添加类型评分 genres = row.Genres.split(',') if len(genres) == 1: genre = genres[0] if genre in avg_genres_ratings: features.append(avg_genres_ratings[genre]) else: features.append(0) features.extend([0, 0]) elif len(genres) == 2: genre_1, genre_2 = genres if genre_1 in avg_genres_ratings: features.append(avg_genres_ratings[genre_1] * 0.6) else: features.append(0) if genre_2 in avg_genres_ratings: features.append(avg_genres_ratings[genre_2] * 0.4) else: features.append(0) features.append(0) else: genre_1, genre_2, genre_3 = genres if genre_1 in avg_genres_ratings: features.append(avg_genres_ratings[genre_1] * 0.4) else: features.append(0) if genre_2 in avg_genres_ratings: features.append(avg_genres_ratings[genre_2] * 0.3) else: features.append(0) if genre_3 in avg_genres_ratings: features.append(avg_genres_ratings[genre_3] * 0.3) else: features.append(0) X.append(features) X = pd.DataFrame(X)
06-01
可以优化的地方有: 1. 使用向量化操作代替迭代操作,可以显著提高代码效率; 2. 缩短代码长度和提高可读性,可以通过使用函数和列表推导式等技巧实现。 以下是优化后的代码: ```python import numpy as np def get_feature(row, avg_runtime_ratings, avg_year_ratings, avg_director_ratings, avg_writer_ratings, avg_casts_ratings, avg_genres_ratings): features = [] # 添加运行时长区间评分 runtime = row.get('RunTime', np.nan) category1 = pd.cut([runtime], bins=bins1, labels=labels1)[0] if pd.notna(runtime) else None if category1 in avg_runtime_ratings: features.append(avg_runtime_ratings[category1]) else: features.append(0) # 添加年份区间评分 year = row.get('year', np.nan) category2 = pd.cut([year], bins=bins2, labels=labels2)[0] if pd.notna(year) else None if category2 in avg_year_ratings: features.append(avg_year_ratings[category2]) else: features.append(0) # 添加导演评分 director = row.get('Director', None) features.append(avg_director_ratings.get(director, 0)) # 添加编剧评分 writer = row.get('Writer', None) features.append(avg_writer_ratings.get(writer, 0)) # 添加主演评分 casts = row.get('TopTwoCasts', '').split(',') if len(casts) == 1: cast = casts[0] features.append(avg_casts_ratings.get(cast, 0)) features.extend([0, 0]) else: cast_1, cast_2 = casts features.append(avg_casts_ratings.get(cast_1, 0) * 0.6) features.append(avg_casts_ratings.get(cast_2, 0) * 0.4) # 添加类型评分 genres = row.get('Genres', '').split(',') if len(genres) == 1: genre = genres[0] features.append(avg_genres_ratings.get(genre, 0)) features.extend([0, 0]) elif len(genres) == 2: genre_1, genre_2 = genres features.append(avg_genres_ratings.get(genre_1, 0) * 0.6) features.append(avg_genres_ratings.get(genre_2, 0) * 0.4) features.append(0) else: genre_1, genre_2, genre_3 = genres features.append(avg_genres_ratings.get(genre_1, 0) * 0.4) features.append(avg_genres_ratings.get(genre_2, 0) * 0.3) features.append(avg_genres_ratings.get(genre_3, 0) * 0.3) return features X = data.apply(lambda row: get_feature(row, avg_runtime_ratings, avg_year_ratings, avg_director_ratings, avg_writer_ratings, avg_casts_ratings, avg_genres_ratings), axis=1) X = pd.DataFrame(X.tolist()) ```

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值