Exemple #1
0
def load_data(path, rng, epoch, batch_size, x_, y_):
    """ load data into shared variables """
    #global x_,t_,y_,
    #global first_report2
    #first_report2 = True
    start_time = time()
    v, p, skeleton_feature, l = load_gzip(path)
    v = v[:, :, :res_shape[2]]
    res_shape[0] = v.shape[0]
    v_new = empty(res_shape, dtype="uint8")

    for i in xrange(v.shape[0]):  #batch
        if p[i] < 10: p[i] = 100
        ofs = p[i] * ratio
        mid = v.shape[-1] / 2.
        sli = None
        if ofs < mid:
            start = int(round(mid - ofs))
            end = int(round(mid + ofs))
            sli = slice(start, end)

        for j in xrange(v.shape[2]):  #maps
            for k in xrange(v.shape[3]):  #frames
                #body
                img = v[i, 0, j, k]
                img = cut_img(img, 5)
                img = misc.imresize(img, (h, h))
                # if j==0: img = 255-misc.imfilter(img,"contour")
                v_new[i, 0, j, k] = img

                #hand
                img = v[i, 1, j, k]
                img = img[sli, sli]
                img = misc.imresize(img, (h, h))
                v_new[i, 1, j, k] = img

    vid, lbl = v_new, l

    #if epoch==0: print "get in",str(time()-start_time)[:3]+"s",
    # shuffle data
    ind = rng.permutation(l.shape[0])
    ind = ind[:batch_size]
    vid = vid[:, :, :, :4, :, :]
    vid, skeleton_feature, lbl = vid[ind].astype(
        floatX), skeleton_feature[ind].astype(floatX), lbl[ind].astype(floatX)
    #vid, skeleton_feature, lbl = vid.astype(floatX), skeleton_feature.astype(floatX),lbl.astype(floatX)

    # vid = vid/(255./(scaler*2.))-scaler
    #traj = traj/(255./(scaler_traj*2.))-scaler_traj
    # traj = traj/(255./5.)

    # Wudi already made labels start from 0
    #lbl -= 1

    #if first_report2:
    #    print "data range:",vid.min(),vid.max()
    #    print "traj range:",skeleton_feature.min(),skeleton_feature.max()
    #    print "lbl range:",lbl.min(),lbl.max()
    #    first_report2 = False

    # set value
    x_.set_value(vid, borrow=True)
    #t_.set_value(skeleton_feature, borrow=True)
    y_.set_value(lbl, borrow=True)
Exemple #2
0
def load_data(path, trans): 
    global rng, x_,t_,y_,first_report2
    """ load data into shared variables """

    # if trans and use.aug:
    #     transform(path) # que up the path for augmentation
    #     vid, traj, lbl = load_aug(path)
    # else:
    #     vid, traj, lbl = load_normal(path)

    # file = GzipFile(path, 'rb')
    # vid, skel, lbl = load(file)
    # file.close()
    # traj,ori,pheight = skel

    # print path
    # import cv2
    # for img in vid[0,0,0]:
    #      cv2.imshow("Video", img)
    #      cv2.waitKey(0)
    # for img in vid[0,0,1]:
    #      cv2.imshow("Video", img)
    #      cv2.waitKey(0)

    # new_vid = empty(in_shape,dtype="uint8")

    # vid_ = vid[:,0,:2,:,::2,::2]
    # vid_ = vid[:,0,:2]
    # zm = 1.*90./128.
    # vid_ = ndimage.zoom(vid_,(1,1,1,zm,zm),order=0)
    # new_vid[:,0] = vid_
    # new_vid[:,1] = vid[:,1,:2]

    # print "loading..."
    start_time = time()
    # if not trans: 
    #     start_load(files.valid,jobs,False)
    # vid, skel, lbl = queue.get()[0]
    v,t,o,p,l = load_gzip(path)
    v = v[:,:,:res_shape[2]]
    v_new = empty(res_shape,dtype="uint8")

    for i in xrange(v.shape[0]): #batch

        if p[i] < 10: p[i] = 100
        ofs = p[i]*ratio
        mid =  v.shape[-1]/2.
        sli = None
        if ofs < mid:
            start = int(round(mid-ofs))
            end = int(round(mid+ofs))
            sli = slice(start,end)

        for j in xrange(v.shape[2]): #maps
            for k in xrange(v.shape[3]): #frames
                #body
                img = v[i,0,j,k]
                img = cut_img(img,5)
                img = misc.imresize(img,(h,h))
                # if j==0: img = 255-misc.imfilter(img,"contour")
                v_new[i,0,j,k] = img

                #hand
                img = v[i,1,j,k]
                img = img[sli,sli]
                img = misc.imresize(img,(h,h))
                v_new[i,1,j,k] = img

    vid, skel, lbl = v_new,(t,o,p),l

    traj,ori,pheight = skel

    if epoch==0: print "get in",str(time()-start_time)[:3]+"s",

    # shuffle data
    ind = rng.permutation(batch_size)
    vid, traj, lbl = vid[ind].astype(floatX), traj[ind].astype(floatX),lbl[ind].astype(floatX)

    # vid = vid/(255./(scaler*2.))-scaler
    traj = traj/(255./(scaler_traj*2.))-scaler_traj
    # traj = traj/(255./5.)

    lbl -= 1

    if first_report2:
        print "data range:",vid.min(),vid.max()
        print "traj range:",traj.min(),traj.max()
        print "lbl range:",lbl.min(),lbl.max()
        first_report2 = False

    # set value
    x_.set_value(vid, borrow=True)
    t_.set_value(traj, borrow=True)
    y_.set_value(lbl, borrow=True)
Exemple #3
0
def load_data(path, trans):
    global rng, x_, t_, y_, first_report2
    """ load data into shared variables """

    # if trans and use.aug:
    #     transform(path) # que up the path for augmentation
    #     vid, traj, lbl = load_aug(path)
    # else:
    #     vid, traj, lbl = load_normal(path)

    # file = GzipFile(path, 'rb')
    # vid, skel, lbl = load(file)
    # file.close()
    # traj,ori,pheight = skel

    # print path
    # import cv2
    # for img in vid[0,0,0]:
    #      cv2.imshow("Video", img)
    #      cv2.waitKey(0)
    # for img in vid[0,0,1]:
    #      cv2.imshow("Video", img)
    #      cv2.waitKey(0)

    # new_vid = empty(in_shape,dtype="uint8")

    # vid_ = vid[:,0,:2,:,::2,::2]
    # vid_ = vid[:,0,:2]
    # zm = 1.*90./128.
    # vid_ = ndimage.zoom(vid_,(1,1,1,zm,zm),order=0)
    # new_vid[:,0] = vid_
    # new_vid[:,1] = vid[:,1,:2]

    # print "loading..."
    start_time = time()
    # if not trans:
    #     start_load(files.valid,jobs,False)
    # vid, skel, lbl = queue.get()[0]
    v, t, o, p, l = load_gzip(path)
    v = v[:, :, :res_shape[2]]
    v_new = empty(res_shape, dtype="uint8")

    for i in xrange(v.shape[0]):  #batch

        if p[i] < 10: p[i] = 100
        ofs = p[i] * ratio
        mid = v.shape[-1] / 2.
        sli = None
        if ofs < mid:
            start = int(round(mid - ofs))
            end = int(round(mid + ofs))
            sli = slice(start, end)

        for j in xrange(v.shape[2]):  #maps
            for k in xrange(v.shape[3]):  #frames
                #body
                img = v[i, 0, j, k]
                img = cut_img(img, 5)
                img = misc.imresize(img, (h, h))
                # if j==0: img = 255-misc.imfilter(img,"contour")
                v_new[i, 0, j, k] = img

                #hand
                img = v[i, 1, j, k]
                img = img[sli, sli]
                img = misc.imresize(img, (h, h))
                v_new[i, 1, j, k] = img

    vid, skel, lbl = v_new, (t, o, p), l

    traj, ori, pheight = skel

    if epoch == 0: print "get in", str(time() - start_time)[:3] + "s",

    # shuffle data
    ind = rng.permutation(batch_size)
    vid, traj, lbl = vid[ind].astype(floatX), traj[ind].astype(
        floatX), lbl[ind].astype(floatX)

    # vid = vid/(255./(scaler*2.))-scaler
    traj = traj / (255. / (scaler_traj * 2.)) - scaler_traj
    # traj = traj/(255./5.)

    lbl -= 1

    if first_report2:
        print "data range:", vid.min(), vid.max()
        print "traj range:", traj.min(), traj.max()
        print "lbl range:", lbl.min(), lbl.max()
        first_report2 = False

    # set value
    x_.set_value(vid, borrow=True)
    t_.set_value(traj, borrow=True)
    y_.set_value(lbl, borrow=True)
def load_data(path, rng, epoch, batch_size, x_,y_): 
    """ load data into shared variables """
    #global x_,t_,y_,
    #global first_report2 
    #first_report2 = True
    start_time = time()
    v,p,skeleton_feature,l = load_gzip(path)
    v = v[:,:,:res_shape[2]]
    res_shape[0] = v.shape[0]
    v_new = empty(res_shape,dtype="uint8")

    for i in xrange(v.shape[0]): #batch
        if p[i] < 10: p[i] = 100
        ofs = p[i]*ratio
        mid =  v.shape[-1]/2.
        sli = None
        if ofs < mid:
            start = int(round(mid-ofs))
            end = int(round(mid+ofs))
            sli = slice(start,end)

        for j in xrange(v.shape[2]): #maps
            for k in xrange(v.shape[3]): #frames
                #body
                img = v[i,0,j,k]
                img = cut_img(img,5)
                img = misc.imresize(img,(h,h))
                # if j==0: img = 255-misc.imfilter(img,"contour")
                v_new[i,0,j,k] = img

                #hand
                img = v[i,1,j,k]
                img = img[sli,sli]
                img = misc.imresize(img,(h,h))
                v_new[i,1,j,k] = img

    vid, lbl = v_new,l

    #if epoch==0: print "get in",str(time()-start_time)[:3]+"s",
    # shuffle data
    ind = rng.permutation(l.shape[0])
    ind = ind[:batch_size]
    vid = vid[:,:,:,:4,:,:]
    vid, skeleton_feature, lbl = vid[ind].astype(floatX), skeleton_feature[ind].astype(floatX),lbl[ind].astype(floatX)
    #vid, skeleton_feature, lbl = vid.astype(floatX), skeleton_feature.astype(floatX),lbl.astype(floatX)

    # vid = vid/(255./(scaler*2.))-scaler
    #traj = traj/(255./(scaler_traj*2.))-scaler_traj
    # traj = traj/(255./5.)

    # Wudi already made labels start from 0
    #lbl -= 1 

    #if first_report2:
    #    print "data range:",vid.min(),vid.max()
    #    print "traj range:",skeleton_feature.min(),skeleton_feature.max()
    #    print "lbl range:",lbl.min(),lbl.max()
    #    first_report2 = False

    # set value
    x_.set_value(vid, borrow=True)
    #t_.set_value(skeleton_feature, borrow=True)
    y_.set_value(lbl, borrow=True)