该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

python新手,做毕设用到,相关程序如下

file_num = g_file_num + int(

filename[filename.find("_")+1:filename.find(".")])

这一行报错:

Traceback (most recent call last):

File "F:\MATLAB\preprocess_cad60.py", line 118, in

extract_images_and_matricize_keypoints()

File "F:\MATLAB\preprocess_cad60.py", line 68, in extract_images_and_matricize_keypoints

filename[filename.find("_")+1:filename.find(".")])

ValueError: invalid literal for int() with base 10: 'activityLabel'

就上面这部分。非常感谢大佬的帮助!!

如果需要看全部代码的话:

#!/usr/bin/env python

# -*- coding: utf-8 -*-

import os

import numpy as np

import pickle as pkl

import scipy.io as sio

import itertools

def remove_orientations_and_make_2d(joint_row):

"""As explained, this function removes all the orientation information and

makes each 3d pose 2d. It will also remove all the confidence bits from the

array"""

joint_row_without_orientations = []

for i in range(11):

del joint_row[:10]

joint_row_without_orientations.extend(joint_row[:3])

del joint_row[:4]

for i in range(4):

joint_row_without_orientations.extend(joint_row[:3])

del joint_row[:4]

joint_row_2d = []

joint_row_norm = []

for i in range(15):

x, y, z = joint_row_without_orientations[:3]

del joint_row_without_orientations[:3]

X = (156.8584456124928 + 0.0976862095248 * x - 0.0006444357104 * y

+ 0.0015715946682 * z)

Y = (125.5357201011431 + 0.0002153447766 * x - 0.1184874093530 * y

- 0.0022134485957 * z)

joint_row_2d.append([X,Y])

joint_row_norm.append([X/320, Y/240])#Normalized

return joint_row_2d, joint_row_norm

def extract_images_and_matricize_keypoints():

""" As the title suggests the following function will modify the title of

each file to match that of the folder in which it lies and then will also

matricize the keypoint file associated with it """

dat_dir = 'data/cad60_dataset'

try:

joints = pkl.load(open(dat_dir+'/joints.p', 'rb'))

except:

joints = []

mat_joints = []

subdir_list = []

for filename in os.listdir(dat_dir):

if os.path.isdir(dat_dir+'/'+filename):

subdir_list.append(filename)

print subdir_list

if not os.path.exists('data/cad60_dataset/images'):

os.mkdir('data/cad60_dataset/images')

g_file_num = 0

for subdir in subdir_list:

if not (subdir == 'images' or subdir == 'mark' or subdir == 'crop'

or subdir == 'joint'):

#Record the number of files (Depth OR RGB) in the folder

num_files_in_folder = int(len(os.listdir(dat_dir+'/'+subdir))/2)

print "Extracting files from dir: {}".format(subdir)

print "Number of files in the current folder:{}".format(

num_files_in_folder)

for filename in os.listdir(dat_dir+'/'+subdir):

file_num = g_file_num + int(

filename[filename.find("_")+1:filename.find(".")])

file_type = filename[0] #R(GB) or D

#Uncomment following line(and comment line below that one)

#if USING MULTIPLE DIRECTORIES from the CAD 60 dataset.

#os.rename(dat_dir+'/'+subdir+'/'+filename,

#dat_dir+'/images/'+subdir+file_num+'_'+file_type+'.jpg')

os.rename(dat_dir+'/'+subdir+'/'+filename,

dat_dir+'/images/'+str(file_num)+'_'+file_type+'.jpg')

print "Finished adding all files. Now extracting joint info"

with open(dat_dir+'/'+subdir+'.txt', 'rU') as txt_file:

lines_list = txt_file.read()

lines_list = lines_list.split('\n')[:-1]

for line in lines_list:

joint_row = line.split(',')[:-1]

if joint_row:

try:

joint_row[1:] = (

[float(joint_str) for joint_str in joint_row[1:]])

except ValueError:

print "[ERROR] Could not convert string to float"

print joint_row

return

joint_row_norm = list(joint_row)

joint_row[1:], joint_row_norm[1:] = (

remove_orientations_and_make_2d(joint_row[1:]))

#MATLAB Stuff

chain_mix = list(joint_row_norm)

chain_mix[0] = [g_file_num + int(chain_mix[0])]

chain = [item for sublist in chain_mix for item in sublist]

mat_joints.append(chain)

#Pickle Stuff

#joint_row[0] = subdir+joint_row[0]#UNCOMMENT if multiple

#directories of CAD60 dataset

joint_row[0] = str(chain_mix[0][0])#Since chain_mix[0] is a list

joints.append(joint_row)

else:

continue

print "Joint number is at {} = Number of files handled?".format(

chain_mix[0])

g_file_num += num_files_in_folder

os.rmdir(dat_dir+'/'+subdir)

print "Number of files handled: {}".format(g_file_num)

pkl.dump(joints, open(dat_dir+'/joints.p', 'wb'))

#sio.savemat(dat_dir+'/joints.mat', {'joints':mat_joints})#Store as mat

if __name__ == '__main__':

extract_images_and_matricize_keypoints()

python invalid literal for int_求助!运行出现错误“ValueError: invalid literal for int() ··...相关推荐

  1. python封装成exe后运行失败_解决Python使用pyinstaller打包生成exe运行提示错误 | kTWO-个人博客...

    最近用python写了个小的桌面程序,在本机上调试的时候,一点问题都没有,在生成exe后也可以正常打开,但是我发给舍友用的时候却突然出现的错误,运行后提示Failed to execute scrip ...

  2. 运行scrapy shell 'http://quotes.toscrape.com'出现错误ValueError: invalid hostname: 'http

    解决办法是把单引号改为双引号,即 scrapy shell "http://quotes.toscrape.com"

  3. ValueError: invalid literal for int() with base 10:Python报错及其解决办法

    https://blog.csdn.net/hanhanwanghaha宝藏女孩 欢迎您的关注! 欢迎关注微信公众号:宝藏女孩的成长日记 如有转载,请注明出处(如不注明,盗者必究) 报错情况 Valu ...

  4. Python中int(input(请输入一个数))报错:ValueError: invalid literal for int() with base 10: '2.7'

    编写下面这段代码: def division():apple = int(input("请输入苹果个数:\n"))children = int(input("请输入孩子个 ...

  5. python的Web框架Django运行报错:Invalid HTTP_HOST header: 'xxx.xx.xxx.xxx:8000'. You may need to add 'xxx.xx'

    python的Web框架Django运行报错:Invalid HTTP_HOST header: 'xxx.xx.xxx.xxx:8000'. You may need to add 'xxx.xx' ...

  6. Python 空字符串转化问题:ValueError: invalid literal for int() with base 10: ' ',原因及解决方法。

    ValueError: invalid literal for int() with base 10: ' ' 翻译: 值异常:以10为基数的int()的无效文字:' ' int('')就会报错. 就 ...

  7. ValueError: invalid literal for int() with base 10

    在运行<机器学习实战>第二章中的代码样例时, 我遇到如下错误: 下面是网上参考文献[1]中的例子 Traceback (most recent call last):   File &qu ...

  8. ValueError: invalid literal for int() with base 10: “ ”

    出现这个错误 :ValueError: invalid literal for int() with base 10: ''  " 或者: ValueError: invalid liter ...

  9. 在使用python语言的open函数时,提示错误OSError: [Errno 22] Invalid argument: ‘文件路径’

    如题,在使用python语言的open函数时,提示错误OSError: [Errno 22] Invalid argument: '文件路径',在查阅了大量资料后也得到了一些解决方案,但是这些解决方案 ...

最新文章

  1. 【CTF】实验吧 robomunication
  2. 超详细面经:无论文、无实习拿下腾讯CV算法岗
  3. typedef和define的详细区别
  4. 网络推广外包——网络推广外包专员如何做好网站首页设计
  5. Windows / Ubuntu操作系统下Pixhawk原生固件PX4的编译方法
  6. 0.Overview----Machine Learning
  7. 数据结构与算法--3.字符串的旋转
  8. Android_activity的生命周期
  9. Oracle数据库迁移:异构传输表空间TTS HP-UX迁移至Redhat Linux 7.7
  10. git 查看pop内容_原创 | 有了Git这个操作,我再也不怕代码混乱了!
  11. 竞斗云2.0刷机-刷原厂固件
  12. Python 基础知识 D5
  13. 3个阶段 项目征名_中资企业新签的3个海外项目开工
  14. 解决PageHelper.startPage(page, size)后total和PageSize总是相等的问题
  15. python 二项分布_如何理解python中的二项分布?
  16. 谈谈写程序与学英语 --宋劲杉
  17. 苹果 M1“痛失”Windows 11!
  18. mysql免安装版,遇到msvcr120dll文件丢失错误的解决方案
  19. 猿来你也在这里,北京上海无聊猿线下见面会成功举办
  20. 12. 整数转罗马数字

热门文章

  1. dropbox免费容量_免费课程:使用ES6和Dropbox构建费用管理器
  2. git 代理 git_五分钟解释Git的要点
  3. 错过了面试,公司招满人了_您可能错过了Google令人赞叹的AI公告。
  4. 电子科技大学计算机应用技术专科段,2020年电子科技大学成都学院计算机应用技术(专科)专业介绍...
  5. docker copy异常
  6. Python 实现邮件发送功能(进阶)
  7. 我用python远程探查女友每天的网页访问记录,她不愧是成年人!
  8. Python中几个有趣的函数
  9. 如何用python写个人专属群聊提醒小助手?
  10. URL重写(使用微软URLRewriter)