def make_variables(feats, labels, use_gpu):
    # Create the input tensors and target label tensors
    # transpose to batch x ch x depth x H x W
    feats = feats.transpose(0, 4, 1, 2, 3)
    feats = torch.from_numpy(np.float32(feats))

    feats[feats == float("-Inf")] = 0
    feats[feats == float("Inf")] = 0
    # Form the target labels
    target = []
    # Append the sequence of labels of len (seq_size-1) to the target list for OF.
    # Iterate over the batch labels, for each extract seq_size labels and extend
    # in the target list

    for i in range(labels[0].size(0)):
        lbls = [y[i] for y in labels]  # get labels of frames (size seq_size)
        # for getting batch x 2 sized matrix, add vectors of size 2
        if sum(lbls) >= 8:
            target.append(1)  # action is True
        else:
            target.append(0)

    # Form a wrap into a tensor variable as B X S X I
    # target is a vector of batchsize
    return utils.create_variable(feats, use_gpu), \
            utils.create_variable(torch.LongTensor(target), use_gpu)
 def create_embedding(self):
     """
      创建embedding variable
     :return:
     """
     # emb_profile_encode = create_variable('emb_profile_encode', shape=(66, 10))
     emb_weekday = create_variable('emb_weekday', shape=(7, 2))
     emb_hour = create_variable('emb_hour', shape=(24, 3))
     return {'emb_weekday': emb_weekday, 'emb_hour': emb_hour}
Example #3
0
 def create_embedding(self):
     """
      创建embedding variable
     :return:
     """
     # emb_profile_encode = create_variable('emb_profile_encode', shape=(66, 10))
     # 'first_mode', 'max_dist_mode', 'min_dist_mode', 'max_price_mode', 'min_price_mode','max_eta_mode', 'min_eta_mode'
     emb_first_mode = create_variable('emb_first_mode', shape=(12, 3))
     emb_max_dist_mode = create_variable('emb_max_dist_mode', shape=(13, 3))
     emb_min_dist_mode = create_variable('emb_min_dist_mode', shape=(13, 3))
     emb_max_price_mode = create_variable('emb_max_price_mode', shape=(13, 3))
     emb_min_price_mode = create_variable('emb_min_price_mode', shape=(13, 3))
     emb_max_eta_mode = create_variable('emb_max_eta_mode', shape=(13, 3))
     emb_min_eta_mode = create_variable('emb_min_eta_mode', shape=(13, 3))
     # date
     emb_weekday = create_variable('emb_weekday', shape=(7, 2))
     emb_hour = create_variable('emb_hour', shape=(24, 3))
     return {
         'emb_first_mode': emb_first_mode,
         'emb_max_dist_mode': emb_max_dist_mode,
         'emb_min_dist_mode': emb_min_dist_mode,
         'emb_max_price_mode': emb_max_price_mode,
         'emb_min_price_mode': emb_min_price_mode,
         'emb_max_eta_mode': emb_max_eta_mode,
         'emb_min_eta_mode': emb_min_eta_mode,
         'emb_weekday': emb_weekday,
         'emb_hour': emb_hour}
Example #4
0
 def _init_hidden(self, batch_size):
      #* self.n_directions
     hidden = torch.zeros(self.n_layers * self.n_directions, batch_size, \
                          self.hidden_size)
     return utils.create_variable(hidden, self.use_gpu)