コード例 #1
0
def read_data(pr, gpus):
  """ This is the code for reading data. We suggest rewriting the I/O code for your own applications"""
  if pr.variable_frame_count:
    #import shift_dset
    import ucf_dset as shift_dset
  else:
    import cls_dset as shift_dset

  with tf.device('/cpu:0'):
    batch = ut.make_mod(pr.batch_size, len(gpus))
    ims, samples, labels = tfu.on_cpu(
      lambda : shift_dset.make_db_reader(
        pr.train_list, pr, batch, ['im', 'samples', 'label'],
        num_db_files = pr.num_dbs))
    
    inputs = {'ims' : ims, 'samples' : samples, 'label' : labels}
    splits = [{} for x in xrange(len(gpus))]      
    for k, v in inputs.items():
      if v is None:
        for i in xrange(len(gpus)):
          splits[i][k] = None
      else:
        s = tf.split(v, len(gpus))
        for i in xrange(len(gpus)):
          splits[i][k] = s[i]

    return splits
コード例 #2
0
def read_data(pr, gpus):
    batch = ut.make_mod(pr.batch_size, len(gpus))

    ims, samples, ytids = on_cpu(
        lambda: sep_dset.make_db_reader(pr.train_list,
                                        pr,
                                        batch, ['im', 'samples', 'ytid'],
                                        num_db_files=pr.num_dbs))

    inputs = {'ims': ims, 'samples': samples, 'ytids': ytids}
    splits = [{} for x in xrange(len(gpus))]
    for k, v in inputs.items():
        if v is None:
            for i in xrange(len(gpus)):
                splits[i][k] = None
        else:
            s = tf.split(v, len(gpus))
            for i in xrange(len(gpus)):
                splits[i][k] = s[i]
    return splits
コード例 #3
0
        print 'Does not exist:', arg.vid_file
        sys.exit(1)

    if arg.duration is None:
        arg.duration = arg.clip_dur + 0.01

    print arg.duration, arg.clip_dur
    full_dur = arg.duration
    #full_dur = min(arg.duration, ut.video_length(arg.vid_file))
    #full_dur = arg.duration
    step_dur = arg.clip_dur / 2.
    filled = np.zeros(int(np.ceil(full_dur * pr.samp_sr)), 'bool')
    full_samples_fg = np.zeros(filled.shape, 'float32')
    full_samples_bg = np.zeros(filled.shape, 'float32')
    full_samples_src = np.zeros(filled.shape, 'float32')
    arg.start = ut.make_mod(arg.start, (1. / pr.fps))

    ts = np.arange(arg.start, arg.start + full_dur - arg.clip_dur, step_dur)
    full_ims = [None] * int(np.ceil(full_dur * pr.fps))

    net = NetClf(pr, gpu=gpus[0])

    for t in ut.time_est(ts):
        t = ut.make_mod(t, (1. / pr.fps))
        frame_start = int(t * pr.fps - arg.start * pr.fps)
        ret = run(arg.vid_file,
                  t,
                  arg.clip_dur,
                  pr,
                  gpus[0],
                  mask=arg.mask,
コード例 #4
0
def good_resample_length(n, new_sr, old_sr, factor2=100):
    factor = new_sr / float(old_sr)
    new_len = int(np.floor(n / factor) * factor)
    return ut.make_mod(new_len, factor2)