# whether use cuda
    use_cuda = torch.cuda.is_available()
    if use_cuda:
        m_cnnblstm_with_adabn = cnnblstm_with_adabn(
            use_cuda=1, params_dir=PARAMS_PATH_SYS,
            enable_CORAL=enable_CORAL).cuda()
    else:
        m_cnnblstm_with_adabn = cnnblstm_with_adabn(use_cuda=0,
                                                    params_dir=PARAMS_PATH_SYS,
                                                    enable_CORAL=enable_CORAL)
    print(m_cnnblstm_with_adabn)
    # get train_x, train_y
    train_x, train_y = tools_6dmg.preprocess(TRAIN_PATH_SYS)
    # enable Kalman
    if enable_Kalman:
        train_x = tools.Kalman_Xs(train_x)
        print(train_x.shape)
    # enable PCA
    if enable_PCA:
        train_x = tools.PCA_Xs(train_x).astype(np.float32)
        print(train_x.shape)
    """
	Y, segments, maxlen_seg, n_files, seq_length = tools.getAllData(TRAIN_PATH)
	train_x, train_y, _ = tools.transferData(Y, segments, n_files, seq_length)
	"""
    # get test_x, test_y
    test_x, test_y = tools_6dmg.preprocess(TEST_PATH_SYS)
    # enable Kalman
    if enable_Kalman:
        test_x = tools.Kalman_Xs(test_x)
        print(test_x.shape)
Example #2
0
	PATH_SYS = sys.argv[2]
	enable_Kalman = (sys.argv[3] == "true")
	enable_PCA = (sys.argv[4] == "true")
	# whether use cuda
	use_cuda = torch.cuda.is_available()
	if use_cuda:
		cnnblstm = cnnblstm(params_file = "./params_6dmg.pkl", use_cuda = use_cuda).cuda()
	else:
		cnnblstm = cnnblstm(params_file = "./params_6dmg.pkl", use_cuda = use_cuda)
	print(cnnblstm)
	if (CMD == "train"):
		# get train_x, train_y
		train_x, train_y = tools_6dmg.preprocess(PATH_SYS)
		# enable Kalman
		if enable_Kalman:
			train_x = tools.Kalman_Xs(train_x).astype(np.float32)
			print(train_x.shape)
		# enable PCA
		if enable_PCA:
			train_x = tools.PCA_Xs(train_x).astype(np.float32)
			print(train_x.shape)
		train_x = torch.from_numpy(train_x)
		train_y = torch.from_numpy(train_y)
		# trainAllLayers
		cnnblstm.trainAllLayers(train_x, train_y, n_epoches = 30)
	elif (CMD == "test"):
		# get test_x, test_y
		test_x, test_y = tools_6dmg.preprocess(PATH_SYS)
		# enable Kalman
		if enable_Kalman:
			test_x = tools.Kalman_Xs(test_x).astype(np.float32)
Example #3
0
		m_transfer_cnnblstm_with_adabn = transfer_cnnblstm_with_adabn(use_cuda = use_cuda, params_dir = PARAMS_PATH, transfer_params_dir = TRANSFER_PARAMS_PATH)
	print(m_transfer_cnnblstm_with_adabn)
	# get transfer_x & transfer_y
	if IS_6DMG:
		transfer_x, transfer_y = tools_6dmg.preprocess(TRANSFER_PATH)
	else:
		Y, segments, maxlen_seg, n_files, seq_length = tools.getAllData(TRANSFER_PATH)
		transfer_x, transfer_y, _ = tools.transferData(Y, segments, n_files, seq_length)
	# get permutation index
	per = np.random.permutation(transfer_x.shape[0])
	# premute transfer_x & transfer_y
	transfer_x = transfer_x[per, :, :]
	transfer_y = transfer_y[per]
	# enable Kalman
	if enable_Kalman:
		transfer_x = tools.Kalman_Xs(transfer_x).astype(np.float32)
		# print(transfer_x.shape)
	# enable PCA
	if enable_PCA:
		transfer_x = tools.PCA_Xs(transfer_x).astype(np.float32)
		# print(transfer_x.shape)
	# get train_x & train_y
	if N_TRAINSET != 0:
		train_x = torch.from_numpy(transfer_x[:N_TRAINSET, :, :])
		train_y = torch.from_numpy(transfer_y[:N_TRAINSET])
		# print(train_x.shape, train_y.shape)
	else:
		train_x, train_y = None, None
	# get test_x & test_y
	if (N_TRAINSET != 0):
		test_x = torch.from_numpy(transfer_x[N_TRAINSET:, :, :])