Exemplo n.º 1
0
	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)
			print(test_x.shape)
		# enable PCA
		if enable_PCA:
			test_x = tools.PCA_Xs(test_x).astype(np.float32)
Exemplo n.º 2
0
		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:, :, :])
		test_y = torch.from_numpy(transfer_y[N_TRAINSET:])
		# print(test_x.shape, test_y.shape)
	elif (N_TESTSET != 0):
		test_x = torch.from_numpy(transfer_x[:N_TESTSET, :, :])