Esempio n. 1
0
  def __init__(self, params, datas, model_dict):
    super(BVA, self).__init__()

    # embedding layer
    self.embeddings = XlingEmbeddingLayer(params, datas)
    # encoder
    self.encoder = Encoder(params)
    
    # discriminator for adversarial training
    self.adv_training = params.adv_training
    if self.adv_training:
      self.discriminator = XlingDiscriminator(params)

    # inferer
    self.inferer = Inferer(params, params.inf_in_dim)

    # vae type
    self.vae_type = params.vae_type

    # decoder
    # untie the embeddings
    if params.tie_emb:
      self.decoder = XlingDecoder(params, datas, self.embeddings)
    else:
      embeddings = copy.deepcopy(self.embeddings)
      """
      # random initialization
      for emb in embeddings.embeddings:
        initrange = 0.5 / 300
        emb.embeddings.weight.data.uniform_(-initrange, initrange)
        emb.embeddings.weight.data[0] = 0
      """
      self.decoder = XlingDecoder(params, datas, embeddings)

    # load pretrained model
    if model_dict is not None:
      self.init_model(self, model_dict)

    # load pretrained embeddings again in case we need
    if model_dict is not None and params.pretrained_emb_path[0] is not None:
      for i, lang in enumerate(self.embeddings.lang_dict):
        if params.pretrained_emb_path[i] is not None:
          vocab = datas[i].vocab
          assert (lang == vocab.lang)
          self.embeddings.embeddings[i].init_emb(
            self.embeddings.embeddings[i].embeddings,
            params.pretrained_emb_path[i],
            vocab)

    self.use_cuda = params.cuda
    if self.use_cuda:
      self.cuda()
Esempio n. 2
0
def run():
    """
    Prepares and runs the whole system.
    """
    args = parse_args()
    logger.info('Args are: {}'.format(args))
    env = Env(args)
    model = env.model
    datasets = env.datasets
    worker = Trainer(args, model=model, datasets=datasets) \
             if not args.is_infer else \
             Inferer(args, model=model, datasets=datasets)
    worker.start()
Esempio n. 3
0
    def __init__(self, params, data_x, data_y):
        super(BVA, self).__init__()
        # encoder
        self.encoder_x = Encoder(params, data_x.vocab)
        self.encoder_y = Encoder(params, data_y.vocab)

        # inferer
        self.inferer = Inferer(params)
        # number of samples from z
        self.sample_n = params.sample_n
        self.ls_type = params.ls_type

        # decoder
        self.decoder = Decoder(params, data_x, data_y)

        self.use_cuda = params.cuda
        if self.use_cuda:
            self.cuda()
Esempio n. 4
0
    def __init__(self, params, data_list, classifier_config, model_dict=None):
        super(CLDCModel, self).__init__()
        # embedding layer
        self.embeddings = XlingEmbeddingLayer(params, data_list)
        # encoder
        self.encoder = Encoder(params)
        # inferer
        self.inferer = Inferer(params, params.inf_in_dim)

        # load pretrained model
        if model_dict is not None:
            XlingVA.init_model(self, model_dict)

        # CLDC classifier
        self.cldc_classifier = CLDCClassifier(params, classifier_config)

        self.use_cuda = params.cuda
        if self.use_cuda:
            self.cuda()
# import lib
FACE_EXPRESSION_SRC_ROOT = "/Vol0/user/k.iskakov/dev/face_expression"
sys.path.append(FACE_EXPRESSION_SRC_ROOT)
from inferer import Inferer

# setup device and checkpoint
device = 'cuda:0'

config_path = "/Vol1/dbstore/datasets/k.iskakov/share/face_expression/gold_checkpoints/siamese+mediapipe_normalization+use_beta-false+checkpoint_000018/config.yaml"
checkpoint_path = "/Vol1/dbstore/datasets/k.iskakov/share/face_expression/gold_checkpoints/siamese+mediapipe_normalization+use_beta-false+checkpoint_000018/checkpoint_000018.pth"

# device = 'cpu'
device = 'cuda:0'
inferer = Inferer(config_path,
                  checkpoint_path,
                  K_rgb,
                  T_depth_to_rgb,
                  device=device)

count = 0
times = []
for fid in tqdm(frame_ids):
    print()
    if fid not in joints_poses_dict:
        continue

    joints_poses = joints_poses_dict[fid]

    # load rgb image
    img_path = root_folder_rgb + '/' + pid_lbl + '/' + dev_lbl + '/color_undistorted/' + str(
        fid).zfill(6) + '.jpg'
Esempio n. 6
0
generator = PCLGen((perspective.DST_HEIGHT, perspective.DST_WIDTH), 50)
if __name__ == "__main__":
    import signal
    import sys

    last = False
    lastPCL = None
    rospy.init_node("freespace_stopper")
    pcl_pub = rospy.Publisher("/seg/pcl", PointCloud, queue_size=10)
    scan_sub = rospy.Subscriber("/scan", LaserScan, callback1)
    forward_pub = rospy.Publisher("/forward", String, queue_size=10)
    image_pub = rospy.Publisher("seg/reg", Image, queue_size=2)
    bridge = CvBridge()

    inferer = Inferer(2502)

    def end(sig, frame):
        print "\n\nClosing TF sessions"
        inferer.sess.close()
        print "done."
        sys.exit(0)
    signal.signal(signal.SIGINT, end)

    cam = WebcamVideoStream(src=1).start()
    while True:
        frame = cam.read()
        start = current_time()
        frame = perspective.undistort_internal(frame)
        frame = frame[240:, :]
        frame = cv2.resize(frame, (480, 180))