提交 e8f2dd86 编写于 作者: K kechxu 提交者: PAN Jiacheng

tools/prediction: reorgnize folders

上级 da4cf422
......@@ -25,7 +25,7 @@ from google.protobuf.internal import decoder
from google.protobuf.internal import encoder
from modules.prediction.proto import offline_features_pb2
from common.bounding_rectangle import BoundingRectangle
from bounding_rectangle import BoundingRectangle
from configure import parameters
param_fea = parameters['feature']
......
......@@ -22,22 +22,9 @@ import glob
import argparse
import logging
from common.configure import parameters
from common.feature_io import load_protobuf
from common.feature_io import save_protobuf
from common.feature_io import build_trajectory
from common.trajectory import TrajectoryToSample
from common.online_to_offline import LabelGenerator
sys.path.append('/apollo/modules/tools/prediction/data_pipelines/common/')
import os
import sys
import glob
import argparse
import logging
from common.configure import parameters
from common.online_to_offline import LabelGenerator
from online_to_offline import LabelGenerator
if __name__ == "__main__":
......
......@@ -20,8 +20,9 @@ import glob
import argparse
import logging
from common.configure import parameters
from common.online_to_offline import LabelGenerator
sys.path.append('/apollo/modules/tools/prediction/data_pipelines/common/')
from online_to_offline import LabelGenerator
if __name__ == "__main__":
......
......@@ -20,8 +20,9 @@ import glob
import argparse
import logging
from common.configure import parameters
from common.online_to_offline import LabelGenerator
sys.path.append('/apollo/modules/tools/prediction/data_pipelines/common/')
from online_to_offline import LabelGenerator
if __name__ == "__main__":
......
......@@ -20,8 +20,9 @@ import glob
import argparse
import logging
from common.configure import parameters
from common.online_to_offline import LabelGenerator
sys.path.append('/apollo/modules/tools/prediction/data_pipelines/common/')
from online_to_offline import LabelGenerator
if __name__ == "__main__":
......
......@@ -31,7 +31,7 @@ source /apollo/scripts/apollo_base.sh
source /apollo/cyber/setup.bash
if [ ${SCENARIO} == "junction" ]; then
python /apollo/modules/tools/prediction/learning_algorithms/data_preprocessing/combine_features_and_labels_for_junction.py ${SRC_FILE} ${LBL_FILE}
python /apollo/modules/tools/prediction/data_pipelines/data_preprocessing/combine_features_and_labels_for_junction.py ${SRC_FILE} ${LBL_FILE}
else
python /apollo/modules/tools/prediction/learning_algorithms/data_preprocessing/combine_features_and_labels.py ${SRC_FILE} ${LBL_FILE}
python /apollo/modules/tools/prediction/data_pipelines/data_preprocessing/combine_features_and_labels.py ${SRC_FILE} ${LBL_FILE}
fi
#!/usr/bin/env bash
###############################################################################
# Copyright 2018 The Apollo Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###############################################################################
SRC_DIR=$1
TARGET_DIR=$2
set -e
# TODO(xiaoxq): Remove after rebuilding docker image.
sudo pip install h5py
source /apollo/scripts/apollo_base.sh
source /apollo/cyber/setup.bash
FLAGFILE=/apollo/modules/prediction/conf/prediction.conf
echo "--prediction_offline_mode" >> ${FLAGFILE}
echo "--prediction_offline_bags=${SRC_DIR}" >> ${FLAGFILE}
echo "--prediction_data_dir=${TARGET_DIR}" >> ${FLAGFILE}
echo "--junction_distance_threshold=30.0" >> ${FLAGFILE}
echo "--noenable_prioritize_obstacles" >> ${FLAGFILE}
sudo mkdir -p ${TARGET_DIR}
# sudo chown apollo:apollo ${TARGET_DIR}
cyber_launch start /apollo/modules/prediction/launch/prediction.launch
for b in $(find ${TARGET_DIR} -iname "*.bin"); do
if [ -e "$b.junction.label" ]; then
echo "skip existing $b.junction.label"
else
echo "Generating junction labels for $b"
python modules/tools/prediction/mlp_train/generate_junction_labels.py \
$b $b.junction.label
fi
if [ -e "$b.junction.label.junction.h5" ]; then
echo "skip existing $b.junction.label.junction.h5"
else
echo "Generating junction h5 for $b"
python modules/tools/prediction/mlp_train/generate_junction_h5.py \
$b.junction.label $b.junction.label.junction.h5
fi
done
for b in $(find ${TARGET_DIR} -iname "*.bin"); do
if [ -e "$b.cruise.label" ]; then
echo "skip existing $b.cruise.label"
else
echo "Generating cruise labels for $b"
python modules/tools/prediction/mlp_train/generate_cruise_labels.py \
$b $b.cruise.label
fi
if [ -e "$b.cruise.label.cruise.h5" ]; then
echo "skip existing $b.cruise.label.cruise.h5"
else
echo "Generating cruise h5 for $b"
python modules/tools/prediction/mlp_train/generate_cruise_h5.py \
$b.cruise.label $b.cruise.label.cruise.h5
fi
done
#!/usr/bin/env python
###############################################################################
# Copyright 2018 The Apollo Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###############################################################################
import os
import sys
import glob
import argparse
import logging
import numpy as np
import h5py
from common.configure import parameters
from common.feature_io import load_protobuf
from common.feature_io import load_label_feature
from common.feature_io import save_protobuf
from common.feature_io import build_trajectory
from common.trajectory import TrajectoryToSample
mlp_feature_size = parameters['cruise_mlp']['dim_input']
num_output = parameters['cruise_mlp']['dim_output']
def extract_mlp_features(filename):
features = load_label_feature(filename)
mlp_features = None
for feature in features:
if not feature.HasField('lane') or \
not feature.lane.HasField('lane_graph'):
continue
lane_seq_sz = len(feature.lane.lane_graph.lane_sequence)
for i in range(lane_seq_sz):
lane_seq = feature.lane.lane_graph.lane_sequence[i]
if len(lane_seq.features.mlp_features) != mlp_feature_size:
continue
mlp_feature = []
for j in range(mlp_feature_size):
mlp_feature.append(lane_seq.features.mlp_features[j])
mlp_feature.append(lane_seq.label)
mlp_feature.append(lane_seq.time_to_lane_edge)
mlp_feature.append(lane_seq.time_to_lane_center)
mlp_feature_np = np.array(mlp_feature)
if mlp_features is None:
mlp_features = mlp_feature_np.reshape(
1, mlp_feature_size+num_output)
else:
mlp_features = np.concatenate(
(mlp_features, mlp_feature_np.reshape(
1, mlp_feature_size+num_output)), axis=0)
if (mlp_features is None) or (np.size(mlp_features) == 0):
return None
return mlp_features
def generate_h5_file(filename, output_file):
features = extract_mlp_features(filename)
if (features is None) or (np.size(features) == 0):
print("Failed to extract mlp features from {}".format(filename))
return
h5_file = h5py.File(output_file, 'w')
h5_file.create_dataset('data', data=features)
h5_file.close()
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Generate H5 files')
parser.add_argument('input', type=str, help='input file')
parser.add_argument('output', type=str, help='output file')
args = parser.parse_args()
print("Creating H5: {} -> {}".format(args.input, args.output))
if os.path.isfile(args.input):
generate_h5_file(args.input, args.output)
else:
print("{} is not a valid file.".format(args.input))
#!/usr/bin/env python
###############################################################################
# Copyright 2018 The Apollo Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###############################################################################
import os
import sys
import glob
import argparse
import logging
import numpy as np
import h5py
from common.configure import parameters
from common.feature_io import load_protobuf
from common.feature_io import load_label_feature
from common.feature_io import save_protobuf
from common.feature_io import build_trajectory
from common.trajectory import TrajectoryToSample
mlp_feature_size = parameters['junction_mlp']['dim_input']
mlp_label_size = parameters['junction_mlp']['dim_output']
def extract_mlp_features(filename):
features = load_label_feature(filename)
mlp_features = None
for fea in features:
if not fea.HasField('junction_feature'):
continue
if len(fea.junction_feature.junction_mlp_feature) != mlp_feature_size or \
len(fea.junction_feature.junction_mlp_label) != mlp_label_size:
continue
mlp_feature = []
for i in range(mlp_feature_size):
mlp_feature.append(fea.junction_feature.junction_mlp_feature[i])
for i in range(mlp_label_size):
mlp_feature.append(fea.junction_feature.junction_mlp_label[i])
mlp_feature_np = np.array(mlp_feature)
if mlp_features is None:
mlp_features = mlp_feature_np.reshape(
1, mlp_feature_size+mlp_label_size)
else:
mlp_features = np.concatenate(
(mlp_features, mlp_feature_np.reshape(1, mlp_feature_size+mlp_label_size)), axis=0)
if (mlp_features is None) or (np.size(mlp_features) == 0):
return
#mlp_features = mlp_features.reshape(
# (np.shape(mlp_features)[0] / (mlp_feature_size + 2),
# (mlp_feature_size + 2)))
return mlp_features
def generate_h5_file(filename, output_file):
features = extract_mlp_features(filename)
if (features is None) or (np.size(features) == 0):
print("Failed to extract mlp features from {}".format(filename))
return
h5_file = h5py.File(output_file, 'w')
h5_file.create_dataset('data', data=features)
h5_file.close()
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Generate H5 files')
parser.add_argument('input', type=str, help='input file')
parser.add_argument('output', type=str, help='output file')
args = parser.parse_args()
print("Creating H5: {} -> {}".format(args.input, args.output))
if os.path.isfile(args.input):
generate_h5_file(args.input, args.output)
else:
print("{} is not a valid file.".format(args.input))
#!/usr/bin/env python
###############################################################################
# Copyright 2018 The Apollo Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###############################################################################
import os
import sys
import glob
import argparse
import logging
import numpy as np
import h5py
from common.configure import parameters
from common.feature_io import load_protobuf
from common.feature_io import load_label_feature
from common.feature_io import save_protobuf
from common.feature_io import build_trajectory
from common.trajectory import TrajectoryToSample
mlp_feature_size = parameters['mlp']['dim_input']
def extract_mlp_features(filename):
features = load_label_feature(filename)
mlp_features = None
for feature in features:
if not feature.HasField('lane') or \
not feature.lane.HasField('lane_graph'):
continue
lane_seq_sz = len(feature.lane.lane_graph.lane_sequence)
for i in range(lane_seq_sz):
lane_seq = feature.lane.lane_graph.lane_sequence[i]
if len(lane_seq.features.mlp_features) != mlp_feature_size:
continue
mlp_feature = []
for i in range(mlp_feature_size):
mlp_feature.append(lane_seq.features.mlp_features[i])
mlp_feature.append(lane_seq.label)
mlp_feature_np = np.array(mlp_feature)
if mlp_features is None:
mlp_features = mlp_feature_np
else:
mlp_features = np.concatenate(
(mlp_features, mlp_feature_np), axis=0)
if (mlp_features is None) or (np.size(mlp_features) == 0):
return
mlp_features = mlp_features.reshape(
(np.shape(mlp_features)[0] / (mlp_feature_size + 1),
(mlp_feature_size + 1)))
return mlp_features
def generate_output(filename, output_file):
features = extract_mlp_features(filename)
if (features is None) or (np.size(features) == 0):
print("Failed to extract mlp features from {}".format(filename))
return
features = features.astype(np.float32)
features.tofile(output_file)
if __name__ == "__main__":
parser = argparse.ArgumentParser(
description='Generate .bin files for tensorflow')
parser.add_argument('input', type=str, help='input file')
parser.add_argument('output', type=str, help='output file')
args = parser.parse_args()
print("Creating .bin: {} -> {}".format(args.input, args.output))
if os.path.isfile(args.input):
generate_output(args.input, args.output)
else:
print("{} is not a valid file.".format(args.input))
#!/usr/bin/env bash
###############################################################################
# Copyright 2019 The Apollo Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
###############################################################################
#
# Use after "apollo.sh build":
# sudo bash /apollo/modules/tools/prediction/mlp_train/scripts/generate_feature_proto.sh <input_dir> <output_dir>
#
# The output feature.X.bin will be in Features proto.
SRC_DIR=$1
TARGET_DIR=$2
set -e
source /apollo/scripts/apollo_base.sh
source /apollo/cyber/setup.bash
FLAGFILE=/apollo/modules/prediction/conf/prediction.conf
echo "--prediction_offline_mode" >> ${FLAGFILE}
echo "--prediction_offline_bags=${SRC_DIR}" >> ${FLAGFILE}
echo "--prediction_data_dir=${TARGET_DIR}" >> ${FLAGFILE}
echo "--junction_distance_threshold=30.0" >> ${FLAGFILE}
echo "--noenable_prioritize_obstacles" >> ${FLAGFILE}
sudo mkdir -p ${TARGET_DIR}
# sudo chown apollo:apollo ${TARGET_DIR}
cyber_launch start /apollo/modules/prediction/launch/prediction.launch
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册