UCF101动作识别数据集简介绍及数据预处理
⽂章⽬录
⼀、数据集简介:
数据集名称:UCF-101(2012)
总视频数:13,320个视频
总时长:27个⼩时
视频来源:YouTube采集
视频类别:101种
主要包括5⼤类动作:⼈与物体交互,单纯的肢体动作,⼈与⼈交互,演奏乐器,体育运动
每个类别(⽂件夹)分为25组,每组4~7个短视频,每个视频时长不等
具体类别:涂抹眼妆,涂抹⼝红,射箭,婴⼉爬⾏,平衡⽊,乐队游⾏,棒球场,篮球投篮,篮球扣篮,卧推,骑⾃⾏车,台球射击,
吹⼲头发,吹蜡烛,体重蹲,保龄球,拳击沙袋,拳击速度袋,蛙泳,刷⽛,清洁和挺举,悬崖跳⽔,板球保龄球,板球射击,在厨房
切割,潜⽔,打⿎,击剑,曲棍球罚款,地板体操,飞盘接球,前爬⽹,⾼尔夫挥杆,理发,链球掷,锤击,倒⽴俯卧撑,倒⽴⾏⾛,
头部按摩,跳⾼,跑马,骑马,呼啦圈,冰舞,标枪掷,杂耍球,跳绳,跳跃杰克,⽪划艇,针织,跳远,刺,阅兵,混合击球⼿,拖
地板,修⼥夹头,双杠,披萨折腾,弹吉他,弹钢琴,弹塔布拉琴,弹⼩提琴,弹⼤提琴,弹Daf,弹Dhol,弹长笛,弹奏锡塔琴,撑
竿跳⾼,鞍马,引体向上,拳打,俯卧撑,漂流,室内攀岩,爬绳,划船,莎莎旋转,剃胡⼦,铅球,滑板溜冰,滑雪,Skijet,跳
伞,⾜球杂耍,⾜球罚球,静环,相扑摔跤,冲浪,秋千,乒乓球拍,太极拳,⽹球秋千,投掷铁饼,蹦床跳跃,打字,⾼低杠,排球
突刺,与狗同⾏,墙上俯卧撑,在船上写字,溜溜球。剃胡须,铅球,滑冰登机,滑雪,Skijet,跳伞,⾜球杂耍,⾜球罚款,静物
环,相扑,冲浪,秋千,乒乓球射击,太极拳,⽹球秋千,掷铁饼,蹦床跳跃,打字,不均匀酒吧,排球突刺,与狗同⾏,壁式俯卧
撑,船上写字,溜溜球。剃胡须,铅球,滑冰登机,滑雪,Skijet,跳伞,⾜球杂耍,⾜球罚款,静物环,相扑,冲浪,秋千,乒乓球
射击,太极拳,⽹球秋千,掷铁饼,蹦床跳跃,打字,不均匀酒吧,排球突刺,与狗同⾏,壁式俯卧撑,船上写字,溜溜球
⼆、数据集获取及解压缩:
1.数据下载
注:数据集⼤⼩为6.46G,数据划分分为三种⽅式,可⾃⾏选择使⽤
2.数据集解压缩:
数据集是rar的压缩⽂件,使⽤rar进⾏解压,cd到对应⽂件夹
解压后就是分类数据集的标准⽬录格式,⼆级⽬录名为⼈类活动类别,⼆级⽬录下就是对应的视频数据。
每个短视频时长不等(零到⼗⼏秒都有),⼤⼩320*240,帧率不固定,⼀般为25帧或29帧,⼀个视频中只包含⼀类⼈类⾏为。
注:本地没有rar,则需安装,在Linux中安装参考,其中要是⾃⼰没有权限可联系管理员让其安装,如果是服务器有使⽤docker,可⽤
chmod命令更改容器权限进⾏安装
三、数据集划分
将下载的UCF101TrainTestSplits-RecognitionTask进⾏解压,解压后如下图所⽰,共三种划分⽅式
⾃⾏选择划分⽅式,本⽂使⽤第⼀种划分⽅法,将验证集移动到val⽂件夹下,划分代码:
importshutil,os
txtlist=['']
datat_dir='./UCF-101/'#数据存放路径
copy_path='./val/'#验证集存放路径
fortxtfileintxtlist:
forlineinopen(txtfile,'r'):
o_filename=datat_dir+()
n_filename=copy_path+()
('/'.join(n_('/')[:-1])):
rs('/'.join(n_('/')[:-1]))
(o_filename,n_filename)
四、数据集预处理
数据处理加载分两种⽅式:先将视频⽂件⽣成pkl⽂件在进⾏处理,或者直接对视频进⾏处理
1.⽣成pkl⽂件
将视频⽂件转换⽣成pkl⽂件,加快数据读取速度,代码:
importos
frompathlibimportPath
importrandom
importcv2
importnumpyasnp
importpickleaspk
fromtqdmimporttqdm
fromPILimportImage
importmultiprocessing
importtime
ormsastransforms
portDataLoader,Datat
classVideoDatat(Datat):
def__init__(l猪肉大葱饺子馅 f,directory,local_rank,num_local_rank,resize_shape=[168,168],mode='val',clip_len=8,frame_sample_rate=2):
folder=Path(directory)#getthedirectoryofthespecifiedsplit
print("Loaddatatfromfolder:",folder)
_len=clip_len
_shape=resize_shape
_sample_rate=frame_sample_rate
=mode
,labels=[],[]
forlabelinsorted(r(folder))[:200]:
r((folder,label)):
((folder,label,fname))
(label)
'''
random_list=list(zip(,labels))
e(random_list)
[:],labels[:]=zip(*random_list)
'''
#prepareamappingbetweenthelabelnames(strings)andindices(ints)
2index={label:indexforindex,labelinenumerate(sorted(t(labels)))}
#convertthelistoflabelnamesintoanarrayoflabelindices
_array=([2index[label]forlabelinlabels],dtype=int)
label_file=str(len(r(folder)))+'class_'
withopen(label_file,'w')asf:
forid,labelinenumerate(sorted(2index)):
ines(str(id+1)+''+label+'n')
ifmode=='train'or'val'andnum_local_rank>1:
single_num_=len()//24
=[local_rank*single_num_:((local_rank+1)*single_num_)]
labels=labels[local_rank*single_num_:((local_rank+1)*single_num_)]
forfileintqdm(,ncols=80):
fname=("/")
ory='/root/datat/{}/{}'.format(fname[-3],fname[-2])
('{}/{}.pkl'.format(ory,fname[-1])):
continue
el:
capture=apture(file)
frame_count=int((_PROP_FRAME_COUNT))
ifframe_count>_len:
buffer=deo(capture,frame_count,file)
el:
whileframe_count<_len:
index=t(lf.__len__())
capture=apture([index])
frame_count=int((_PROP_FRAME_COUNT))
buffer=deo(capture,frame_count,file)
def__getitem__(lf,index):
#vethemtotransformclass
returnindex
def__len__(lf):
returnlen()
defloadvideo(lf,capture,frame_count,fname):
#initializeaVideoCaptureobjecttoreadvideodataintoanumpyarray
orm_nor=e([
([224,224]),
])
#vedtypefloat,soitgetsconvertedtoaFloatTensorbyPytorchlater
start_idx=0
end_idx=frame_count-1
frame_count_sample=frame_count//_sample_rate-1
ifframe_count>300:
end_idx=t(300,frame_count)
start_idx=end_idx-300
start_idx=end_idx-300
frame_count_sample=301//_sample_rate-1
buffer_normal=((frame_count_sample,224,224,3),('uint8'))
count=0
retaining=True
sample_count=0
#readineachframe,oneatatimeintothenumpybufferarray
while(count<=end_idxandretaining):
retaining,frame=()
ifcount
count+=1
continue
ifretainingisFalorcount>end_idx:
break
ifcount%_sample_rate==(_sample_rate-1)andsample_count
frame=ray(or(frame,_BGR2RGB))
buffer_normal[sample_count]=orm_nor(frame)
sample_count+=1
count+=1
fname=("/")
ory='/root/datat/{}/{}'.format(fname[-3],fname[-2])
(ory):
rs(ory)
#e
withopen('{}/{}.pkl'.format(ory,fname[-1]),'wb')asNormal_writer:
(buffer_normal,Normal_writer)
e()
returnbuffer_normal
if__name__=='__main__':
datapath='/root/datat/UCF101'
process_num=24
foriinrange(process_num):
p=s(target=VideoDatat,args=(datapath,i,process_num))
()
print('CPUcorenumber:'+str(_count()))
_children():
print('⼦进程'++'id:'+str())
print('alldone')
之后对pkl⽂件进⾏处理
importos
frompathlibimportPath
importrandom
importcv2
importnumpyasnp
importpickleaspk
fromtqdmimporttqdm
fromPILimportImage
ormsastransforms
portDataLoader,Dat魏晋南北朝 at
classVideoDatat(Datat):
def__init__(lf,directory_list,local_rank=0,enable_GPUs_num=0,distributed_load=Fal,resize_shape=[224,224],mode='train',clip_len=32,crop_s
ize=160):
_len,_size,_shape=clip_len,crop_size,resize_shape
=mode
,labels=[],[]
#getthedirectoryofthespecifiedsplit
fordirectoryindirectory_list:
folder=Path(directory)
print("Loaddatatfromfolder:",folder)
forlabelinsorted(r(folder)):
r((folder,label))ifmode=="train"r((folder,label))[:10]:
((folder,label,fname))
(label)
random_list=list(zip(,labels))
e(random_list)
[:],labels[:]=zip(*random_list)
#=[:240]
'''
ifmode=='train'anddistributed_load:
single_num_=len()//enable_GPUs_num
=[local_rank*single_num_:((local_rank+1)*single_num_)]
labels=labels[local_rank*single_num_:((local_rank+1)*single_num_)]
'''
#prepareamappingbetweenthelabelnames(strings)andindices(ints)
2index={label:indexforindex,labelinenumerate(sorted(t(labels)))}
#convertthelistoflabelnamesintoanarrayoflabelindices
_array=([2index[label]forlabelinlabels],dtype=int)
def__getitem__(lf,index):
#vethemtotransformclasss
buffer=deo([index])
=='train':
height_index=t([2]-_size)
width_index=t([3]-_size)
returnbuffer[:,:,height_index:height_index+_size,width_index:width_index+_size],_array[index]
el:
returnbuffer,_array[index]
def__len__(lf):
returnlen()
defloadvideo(lf,fname):
#initializeaVideoCaptureobjecttoreadvideodataintoanumpyarray
withopen(fname,'rb')asVideo_reader:
video=(Video_reader)
[0]<_len+2:
index=t(lf.__len__())
withopen([index],'rb')asVideo_reader:
video=(Video_reader)
height,width=[1],[2]
height,width=[1],[2]
center=(height//2,width//2)
flip,flipCode=()<0.5elFal,1
#rotation,rotationCode=()<0.2elFal,([-270,-180,-90,90,180,270])
speed_rate=t(1,3)[0]>_len*2+=="train"el1
time_in调查的近义词 dex=t([0]-_len*speed_rate)
video=video[time_index:time_index+(_len*speed_rate):speed_rate,:,:,:]
orm=e([
([_shape[0],_shape[1]]),
or(),
ize([0.5,0.5,0.5],[0.5,0.5,0.5])
])
orm_val=e([
([_size,_size]),
or(),
ize([0.5,0.5,0.5],[0.5,0.5,0.5])
])
=='train':
#vedtypefloat,soitgetsc还要的拼音 onvertedtoaFloatTensorbyPytorchlater
buffer=((_len,3,_shape[0],_shape[1]),('float16'))
foridx,frameinenumerate(video):
iffl1967年属什么生肖属相 ip:
frame=(frame,flipCode=flipCode)
'''
ifrotation:
rot_mat=ationMatrix2D(center,rotationCode,1)
frame=fine(frame,rot_mat,(height,width))
'''
buffer[idx]=orm(ray(frame))
=='validation':
#vedtypefloat,soitgetsconvertedtoaFloatTensorbyPytorchlater
buffer=((_len,3,_size,_size),('float16'))
foridx,frameinenumerate(video):
buffer[idx]=orm_val(ray(frame))
o((1,0,2,3))
if__name__=='__main__':
datapath=['/root/data2/datat/UCF-101']
datat=VideoDatat(datapath,
resize_shape=[224,224],
mode='validation')
dataloader=DataLoader(datat,batch_size=16,shuffle=True,num_workers=0)
bar=tqdm(total=len(dataloader),ncols=80)
forstep,(buffer,labels)inenumerate(dataloader):
print()
print("label:",labels)
(1)
2.直接对视频⽂件处理
总体处理过程与pkl⽂件类似,只是处理主体变成了视频⽂件,代码:
importos
importos
frompathlibimportPath
importrandom
importnumpyasnp
importpickleaspk
importcv2
fromtqdmimporttqdm
fromPILimportImage
ormsastransforms
importtorch
fromprefetch_generatorimportBackgroundGenerator
portDataLoader,Datat
classVideoDatat(Datat):
def__init__(lf,directory_list,local_rank=0,enable_GPUs_num=0,distributed_load=Fal,resize_shape=[224,224],mode='train',clip_len=32,crop_s
ize=168):
_len,_size,_shape=clip_len,crop_size,resize_shape
=mode
,labels=[],[]
#getthedirectoryofthespecifiedsplit
fordirectoryindirectory_list:
folder=Path(directory)
print("Loaddatatfromfolder:",folder)
forlabelinsorted(r(folder)):
r((folder,label))ifmode=="train"r((folder,label))[:10]:
((folder,label,fnam考研报名费用 e))
(label)
random_list=list(zip(,labels))
e(random_list)
[:],labels[:]=zip(*random_list)
#=[:240]
ifmode=='train'anddistributed_load:
single_num_=len()//enable_GPUs_num
=[local_rank*single_num_:((local_rank+1)*single_num_)]
labels=labels[local_rank*single_num_:((local_rank+1)*single_num_)]
#prepareamappingbetweenthelabelnames(strings)andindices(ints)
2index={label:indexforindex,labelinenumerate(sorted(t(labels)))}
#convertthelistoflabelnamesintoanarrayoflabelindices
_array=([2index[label]forlabelinlabels],dtype=int)
def__getitem__(lf,index):
#vethemtotransformclasss
buffer=deo([index])
height_index=t([2]-_size)
width_index=t([3]-_size)
returnbuffer[:,:,height_index:height_index+_size,width_index:width_index+_size],_array[index]
def__len__(lf):
returnlen()
defloadvideo(lf,fname):
#initializeaVideoCaptureobjecttoreadvideodataintoanumpyarray
orm=e([
([_shape[0],_shape[1]]),
or(),
ize([0.5,0.5,0.5],[0.5,0.5,0.5])
])
flip,flipCode=1,([-1,0,1])()<=="train"el0
try:
video_stream=apture(fname)
frame_count=int(video_(_PROP_FRAME_COUNT))
exceptRuntimeError:
index=t(lf.__len__())
video_stream=apture([i水痘的症状 ndex])
frame_count=int(video_(_PROP_FRAME_COUNT))
whileframe_count<_len+2:
index=t(lf.__len__())
video_stream=apture([index])
frame_count=int(video_(_PROP_FRAME_COUNT))
speed_rate=t(1,3)ifframe_count>_len*2+2el1
time_index=t(frame__len*speed_rate)
start_idx,end_idx,final_idx=time_index,time_index+(_len*speed_rate),frame_count-1
count,sample_cou解除劳动关系通知书 nt,retaining=0,0,True
#ve择天记陈长生身世 dtypefloat,soitgetsconvertedtoaFloatTensorbyPytorchlater
buffer=((_len,3,_shape[0],_shape[1]),('float16'))
while(count<=end_idxandretaining):
retaining,frame=video_()
ifcount
count+=1
continue
ifcount%speed_rate==speed_rate-1andcount>=start_idxandsample_count<_len:
ifflip:
frame=(frame,flipCode=flipCode)
try:
buffer[sample_count]=orm(ray(or(frame,_BGR2RGB)))
rr:
continue
sample_count+=1
count+=1
video_e()
o((1,0,2,3))
if__name__=='__main__':
datapath=['/root/data1/datats/UCF-101']
datat=VideoDatat(datapath,
resize_shape=[224,224],
mode='validation')
dataloader=DataLoader(datat,batch_size=8,shuffle=True,num_workers=24,pin_memory=True)
bar=tqdm(total=len(dataloader),ncols=80)
prefetcher=DataPrefetcher(BackgroundGenerator(dataloader),0)
prefetcher=DataPrefetcher(BackgroundGenerator(dataloader),0)
batch=()
iter_id=0
whilebatchisnotNone:
iter_id+=1
(1)
ifiter_id>=len(dataloader):
break
batch=()
print(batch[0].shape)
print("label:",batch[1])
'''
forstep,(buffer,labels)inenumerate(BackgroundGenerator(dataloader)):
print()
print("label:",labels)
(1)
'''
本文发布于:2023-03-25 04:08:35,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/3b4e059b6fc149e1e1318e927bf4ba55.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:悬崖跳水.doc
本文 PDF 下载地址:悬崖跳水.pdf
留言与评论(共有 0 条评论) |