In [1]:
from work.training.generator import VideoDatasetGenerator
from work.dataset.activitynet import ActivityNetDataset

In [2]:
dataset = ActivityNetDataset(
    videos_path='/imatge/amontes/work/activitynet/dataset/videos.json',
    labels_path='/imatge/amontes/work/activitynet/dataset/labels.txt',
    stored_videos_path='/imatge/amontes/work/datasets/ActivityNet/v1.3/videos',
    files_extension='mp4'
)
dataset.generate_instances()
print('Length of the dataset instances:', len(dataset.instances))
samples_per_epoch = len(dataset.instances_training)
print('Length of the training dataset instances:',  samples_per_epoch)

# this should be a dictionary
class_weigths = dataset.compute_class_weights()
print('Computed class weights')


19757/19757 [==============================] - 166s   
('Length of the dataset instances:', 4077203)
('Length of the training dataset instances:', 2053437)
Computed class weights

In [3]:
generator = VideoDatasetGenerator(
    samplewise_center=True,
    samplewise_std_normalization=True,
    rotation_range=0.,
    width_shift_range=0.,
    height_shift_range=0.,
    horizontal_flip=False,
    vertical_flip=False,
    temporal_flip=False
)

In [8]:
g = generator.flow(dataset, 'training', size=(112, 112), length=16, channels=3, batch_size=3, shuffle=True)

In [9]:
X, Y = g.next()
print('X shape {}'.format(X.shape))
print('Y shape {}'.format(Y.shape))


X shape (3, 3, 16, 112, 112)
Y shape (3, 201)

In [12]:
print(X[0])
print(Y[2])


[[[[ 0.01128689 -0.45508578 -0.4631699  ..., -0.04160171 -0.71512651
    -0.77425021]
   [ 0.56153148 -0.20220478 -0.52764893 ..., -0.07467658 -0.71525645
    -0.7745226 ]
   [ 1.16054118  0.55802894  0.35727531 ..., -0.13330464 -0.77456337
    -0.76870251]
   ..., 
   [ 1.39285541  0.68935901  1.00760031 ...,  3.734972   -0.37114993
    -0.76478016]
   [ 1.25369632  0.40113029  1.39941907 ...,  3.7933712  -0.29739049
    -0.71858245]
   [ 0.69399405  0.52092695  1.71793807 ...,  3.57760406 -0.54724115
    -0.67647445]]

  [[-0.4401888  -0.37622616  0.43813369 ..., -0.84035462 -0.78107476
    -0.77425021]
   [-0.21567471 -0.34165636  0.30874813 ..., -0.83803719 -0.78102714
    -0.7745226 ]
   [ 0.63470304  0.37826124  0.59179443 ..., -0.83365136 -0.77456337
    -0.76870251]
   ..., 
   [ 1.89446247  0.60418725 -0.07566959 ..., -0.47151521 -0.73658985
    -0.76478016]
   [ 1.25369632  0.84994739  0.08231877 ..., -0.4220278  -0.76160979
    -0.71858245]
   [ 0.64811009  1.16206777  0.21627249 ..., -0.49307445 -0.59102046
    -0.67647445]]

  [[-0.10910662  0.46494323  0.71353203 ..., -0.84035462 -0.78107476
    -0.77425021]
   [-0.27785122  0.60661435  0.77922148 ..., -0.83803719 -0.78102714
    -0.7745226 ]
   [ 0.40464884  0.67787409  0.67973912 ..., -0.83365136 -0.77456337
    -0.76870251]
   ..., 
   [ 1.82280433 -0.46045989  0.1154957  ..., -0.47151521 -0.73658985
    -0.76478016]
   [ 1.7370491  -0.36185879  1.27398086 ..., -0.4220278  -0.76160979
    -0.71858245]
   [ 0.96929741 -0.2270707   2.10967684 ..., -0.49307445 -0.59102046
    -0.67647445]]

  ..., 
  [[-1.07225478 -1.16482246 -1.23929238 ...,  1.25637174  1.29629564
     1.29598224]
   [-1.14832211 -1.20625615 -1.20722151 ...,  1.25290716  1.32363546
     1.29634941]
   [-1.27146006 -1.26960957 -1.25504398 ...,  1.29922283  1.28023684
     1.42876172]
   ..., 
   [-1.04352188 -1.14183402 -1.1589396  ...,  0.12287972  0.90788984
     1.51456463]
   [-1.1630677  -1.16972959 -1.0466243  ..., -0.03171307  0.74710292
     0.90075827]
   [-1.14136207 -1.2956388  -1.08952367 ..., -0.20488481  0.15322752
     1.30586827]]

  [[-1.04215634 -1.13853586 -1.16418386 ...,  1.22309041  1.26332152
     1.329373  ]
   [-1.14832211 -1.17836583 -1.18108404 ...,  1.2197175   1.25786471
     1.29634941]
   [-1.23859525 -1.26960957 -1.28435886 ...,  1.29922283  1.31234312
     1.39596379]
   ..., 
   [-0.97186375 -1.05666232 -1.03149605 ...,  0.07715704  0.26836994
     1.69451296]
   [-1.1026485  -1.16972959 -1.10934341 ...,  0.04634988  0.74710292
     1.06269228]
   [-1.14136207 -1.18878198 -0.89365423 ..., -0.16886111 -0.15322752
     0.19575635]]

  [[-0.92176288 -1.08596277 -1.11411142 ...,  1.25637174  1.29629564
     1.36276388]
   [-1.05505741 -1.1504755  -1.18108404 ...,  1.28609669  1.29075015
     1.32922041]
   [-1.14000058 -1.32953215 -1.34298861 ...,  1.33105671  1.31234312
     0.83839822]
   ..., 
   [-0.97186375 -1.09924817 -1.09521782 ...,  0.03143435  0.35972995
     0.91473705]
   [-1.1026485  -1.16972959 -1.0466243  ...,  0.04634988  0.63104808
     0.09108792]
   [-1.09547818 -1.18878198 -0.89365423 ..., -0.06079    -0.19700682
    -0.1214185 ]]]


 [[[ 1.17930424  1.18561769  0.79140782 ..., -0.08431065 -0.71767151
    -0.77427161]
   [ 1.05381536  1.2420516   0.52468896 ..., -0.11536317 -0.71767151
    -0.77452707]
   [ 1.33476508  1.28661382  0.74559754 ..., -0.16936092 -0.77457643
    -0.77022398]
   ..., 
   [ 1.12020254 -0.10177019 -0.35731536 ...,  3.84293437 -0.12723714
    -0.73716104]
   [ 0.46179923 -0.44632742 -0.09843423 ...,  3.85407138  0.05051479
    -0.73191786]
   [ 0.12998889 -0.62673336  0.12288563 ...,  3.82067752 -0.19169182
    -0.67450023]]

  [[ 1.07767653  0.64841741  0.31613877 ..., -0.83722436 -0.78059065
    -0.77427161]
   [ 0.90623504  0.47771215  0.41374153 ..., -0.83491647 -0.78059065
    -0.77452707]
   [ 1.044204    0.73131233  0.7861743  ..., -0.8310501  -0.77457643
    -0.77022398]
   ..., 
   [ 0.38864172 -0.0223398   0.03878481 ..., -0.35578054 -0.75363535
    -0.73716104]
   [-0.24766283  0.31146589  0.15093249 ..., -0.33286116 -0.75772184
    -0.73191786]
   [-0.52910972  0.53370875  0.23854269 ..., -0.38062236 -0.61473578
    -0.67450023]]

  [[ 0.63729006  0.41339236  0.68956441 ..., -0.83722436 -0.78059065
    -0.77427161]
   [ 0.38970414  0.51410925  0.82054883 ..., -0.83491647 -0.78059065
    -0.77452707]
   [ 0.71732277  0.73131233  0.82675099 ..., -0.8310501  -0.77457643
    -0.77022398]
   ..., 
   [ 0.40896285  0.1497594   0.59332502 ..., -0.35578054 -0.75363535
    -0.73716104]
   [ 0.72135854  0.18302634  0.89903259 ..., -0.33286116 -0.75772184
    -0.73191786]
   [ 0.75979424  0.30666575  0.97103739 ..., -0.38062236 -0.61473578
    -0.67450023]]

  ..., 
  [[-1.19200766 -1.29893327 -1.31335497 ...,  1.29603112  1.26428163
     1.2958436 ]
   [-1.23367882 -1.30574656 -1.2874527  ...,  1.29245853  1.26428163
     1.296188  ]
   [-1.28028488 -1.29157186 -1.24266255 ...,  1.2800535   1.28567803
     1.40059698]
   ..., 
   [-1.25737023 -1.16084218 -1.20232904 ..., -0.03280246  0.96895975
     1.60225916]
   [-1.23398817 -1.15274489 -1.20089757 ..., -0.06489746 -0.21889742
     0.62405628]
   [-1.18820834 -1.18172741 -1.25214827 ..., -0.14935814 -0.19169182
     1.3966924 ]]

  [[-1.15813172 -1.26535833 -1.21151161 ...,  1.32740247  1.32720077
     1.32818913]
   [-1.23367882 -1.26934946 -1.25047016 ...,  1.32374346  1.32720077
     1.296188  ]
   [-1.20764458 -1.25190747 -1.28323925 ...,  1.31156242  1.31737423
     1.36719978]
   ..., 
   [-1.27769136 -1.17408049 -1.21553242 ..., -0.07317472  0.18596198
     2.08963847]
   [-1.21668422 -1.17843282 -1.24027133 ..., -0.09839292  0.85875142
     1.85676003]
   [-1.18820834 -1.15650034 -1.21359599 ..., -0.1108141  -0.29745281
     0.306591  ]]

  [[-1.19200766 -1.19820833 -1.14361608 ...,  1.29603112  1.35866034
     1.36053467]
   [-1.27057385 -1.23295224 -1.25047016 ...,  1.32374346  1.35866034
     1.32804513]
   [-1.1350044  -1.33123636 -1.36439276 ...,  1.31156242  1.28567803
     0.8996383 ]
   ..., 
   [-1.27769136 -1.17408049 -1.21553242 ..., -0.07317472  0.34256154
     1.30983162]
   [-1.21668422 -1.17843282 -1.2533958  ..., -0.09839292  1.12816358
     0.37751552]
   [-1.17356169 -1.18172741 -1.27784991 ..., -0.1108141   0.12559119
    -0.23845966]]]


 [[[ 1.43622243  1.54264188  1.36032593 ..., -0.16627437 -0.77451241
    -0.77427161]
   [ 1.31223333  1.42404771  1.01766253 ..., -0.10864919 -0.7174992
    -0.77452707]
   [ 1.19675982  1.38560855  1.07656825 ..., -0.08501428 -0.77457643
    -0.76980889]
   ..., 
   [ 1.09685051 -0.18821634 -0.49649402 ...,  3.82402992 -0.55381864
    -0.74820793]
   [ 0.50276846 -0.55450624 -0.22190616 ...,  3.84568715  0.14204775
    -0.68779397]
   [ 0.15362744 -0.69819552  0.17682327 ...,  3.76690626 -0.3632471
    -0.67257583]]

  [[ 1.59470224  1.16866803  0.25127041 ..., -0.8313719  -0.77451241
    -0.77427161]
   [ 1.45967531  0.94812578  0.13997589 ..., -0.83561105 -0.7807498
    -0.77452707]
   [ 1.25357926  1.01559901  0.48899779 ..., -0.78094512 -0.77457643
    -0.76980889]
   ..., 
   [ 0.06294093 -0.09200351  0.31448463 ..., -0.3798016  -0.69014323
    -0.74820793]
   [-0.46301812  0.21291167  0.45305842 ..., -0.34517783 -0.76705784
    -0.68779397]
   [-0.66227627  0.57125086  0.53390324 ..., -0.41903782 -0.59807348
    -0.67257583]]

  [[ 1.11926305  0.23373361  0.41762874 ..., -0.8313719  -0.77451241
    -0.77427161]
   [ 0.84041911  0.29373309  0.53342164 ..., -0.83561105 -0.7807498
    -0.77452707]
   [ 0.85584307  0.64558953  0.61269683 ..., -0.84421152 -0.77457643
    -0.76980889]
   ..., 
   [ 0.15693271  0.45640957  0.60017025 ..., -0.3798016  -0.69014323
    -0.74820793]
   [ 0.46743482  0.54982686  0.82290202 ..., -0.34517783 -0.76705784
    -0.68779397]
   [ 0.76297325  0.62565571  0.90013915 ..., -0.41903782 -0.59807348
    -0.67257583]]

  ..., 
  [[-1.15227962 -1.23544908 -1.27368104 ...,  1.2906059   1.27508783
     1.2958436 ]
   [-1.16479135 -1.25301325 -1.2522167  ...,  1.2820605   1.27489519
     1.296188  ]
   [-1.24647677 -1.29696047 -1.27371359 ...,  1.2752142   1.28567803
     1.40959644]
   ..., 
   [-1.22608924 -1.16958714 -1.19688463 ...,  0.03641933  0.53677803
     1.55028689]
   [-1.19324696 -1.16282523 -1.21123779 ..., -0.0527919   0.59660053
     0.43867174]
   [-1.16834319 -1.18783915 -1.26980853 ..., -0.17071912  0.22381893
     1.13983905]]

  [[-1.12586629 -1.20873666 -1.19050181 ...,  1.2906059   1.30662012
     1.32818913]
   [-1.16479135 -1.22326815 -1.22195172 ...,  1.2820605   1.30652058
     1.296188  ]
   [-1.30329621 -1.42029691 -1.42833734 ...,  1.30684733  1.31737423
     1.37657511]
   ..., 
   [-1.26637149 -1.2080723  -1.23374736 ..., -0.00520276 -0.00852029
     2.02914   ]
   [-1.20502496 -1.19090152 -1.24822211 ..., -0.0527919   0.14204775
     1.21853268]
   [-1.16834319 -1.1697042  -1.2423408  ..., -0.13524501 -0.42195371
     0.4035455 ]]

  [[-1.09945309 -1.28887391 -1.21822822 ...,  1.2906059   1.33815253
     1.36053467]
   [-1.43018687 -1.37199378 -1.34301186 ...,  1.31366754  1.33814585
     1.32804513]
   [-1.27488649 -1.29696047 -1.36648786 ...,  1.30684733  1.28567803
     0.88125575]
   ..., 
   [-1.27979887 -1.2080723  -1.23374736 ..., -0.04682485  0.53677803
     1.16720438]
   [-1.20502496 -1.19090152 -1.27596045 ..., -0.0527919   0.59660053
    -0.08123551]
   [-1.15801525 -1.19690657 -1.28812027 ..., -0.09977091 -0.1284207
    -0.27611008]]]]
[ 1.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
  0.  0.  0.]

In [ ]: