From 2d50941abdd3b7fc746ed386a3bc1d6fddfdd7e0 Mon Sep 17 00:00:00 2001 From: Marina Moreira <67443181+marinagmoreira@users.noreply.github.com> Date: Wed, 28 Feb 2024 13:42:22 -0800 Subject: [PATCH] GMM cleanup recommended by Jamie (#153) --- .../scripts/gmm/gmm_change_detection.py | 24 ---------- .../scripts/gmm/preprocess_data.py | 45 ------------------- .../scripts/gmm/visualization.py | 19 ++++++++ 3 files changed, 19 insertions(+), 69 deletions(-) diff --git a/anomaly/gmm-change-detection/scripts/gmm/gmm_change_detection.py b/anomaly/gmm-change-detection/scripts/gmm/gmm_change_detection.py index b0e62348..6ba48346 100755 --- a/anomaly/gmm-change-detection/scripts/gmm/gmm_change_detection.py +++ b/anomaly/gmm-change-detection/scripts/gmm/gmm_change_detection.py @@ -47,30 +47,6 @@ def gmm_change_detection( n_appearances=0, ): - # Path to input data (.pk for pickled GMMs, PCL file, - # or bag files cropped to same positions at different times) - - # input1 = './data/ground_truth/ground_truth_run5.pcd' - # input2 = './data/ground_truth/ground_truth_run4.pcd' - - # input2 = "./data/single_frame_bags/20230313_1901_survey_no_bag_panorama_precut.bag" - # input1 = "./data/single_frame_bags/20230313_1908_survey_bag_panorama_precut.bag" - - # input1 = './data/single_frame_bags/run5_astrobee.bag' - # input2 = './data/single_frame_bags/run1_astrobee.bag' - - # input1 = './data/image_reconstruction/run5.pcd' - # input2 = './data/image_reconstruction/run2.pcd' - - # input1 = './saved_models/fake_data_t0_1.pk' - # input2 = './saved_models/fake_data_t1_1.pk' - - # input1 = './saved_models/20230313_1901_survey_no_bag_panorama_precut_1.pk' - # input2 = './saved_models/20230313_1908_survey_bag_panorama_precut_1.pk' - - # input1 = 'data/image_reconstruction/run5.pcd' - # input2 = 'data/image_reconstruction/run4.pcd' - # Get file extension ext = os.path.splitext(os.path.basename(input1))[1] current_dir = os.getcwd() diff --git a/anomaly/gmm-change-detection/scripts/gmm/preprocess_data.py b/anomaly/gmm-change-detection/scripts/gmm/preprocess_data.py index 02c308db..b304475d 100644 --- a/anomaly/gmm-change-detection/scripts/gmm/preprocess_data.py +++ b/anomaly/gmm-change-detection/scripts/gmm/preprocess_data.py @@ -48,30 +48,8 @@ # See https://stackoverflow.com/questions/39772424 def convert_pc2_pcl(data): - - # # Convert the PointCloud2 message to a list of points - # points = list(sensor_msgs.read_points(msg, field_names=("x", "y", "z"), skip_nans=True)) - - # data.__class__ = sensor_msgs.msg._PointCloud2.PointCloud2 - # offset_sorted = {f.offset: f for f in data.fields} - # data.fields = [f for (_, f) in sorted(offset_sorted.items())] # Conversion from PointCloud2 msg to np array. np_points = ros_numpy.point_cloud2.pointcloud2_to_xyz_array(data, remove_nans=True) - # np_points=np.zeros((pc.shape[0],3)) - - # height = pc.shape[0] - # if len(pc.shape) == 1: # Unordered PC2 structure - # np_points = np.zeros((height, 3), dtype=np.float32) - # np_points[:, 0] = np.resize(pc["x"], height) - # np_points[:, 1] = np.resize(pc["y"], height) - # np_points[:, 2] = np.resize(pc["z"], height) - - # else: # Ordered PC2 structure - # width = pc.shape[1] - # np_points = np.zeros((height * width, 3), dtype=np.float32) - # np_points[:, 0] = np.resize(pc["x"], height * width) - # np_points[:, 1] = np.resize(pc["y"], height * width) - # np_points[:, 2] = np.resize(pc["z"], height * width) return np_points @@ -191,29 +169,6 @@ def read_pc2_msgs(bagfile): return merged_pcl -# # Process data from bagfile -# def read_pc2_msgs(bagfile): - - -# for topic, msg, t in rosbag.Bag(bagfile).read_messages(): -# if topic == "/hw/depth_haz/extended/amplitude_int": -# np_im = ros_numpy.image.image_to_numpy(msg) -# data = Image.fromarray(np_im) - -# if ( -# topic == "/hw/depth_haz/points" -# or topic == "/hw/depth_haz/points/ground_truth" -# ): -# p = convert_pc2_pcl(msg) -# np_arr = filter_pcl(p) - -# if "data" in locals(): -# data.show() -# data.save("image.png") -# return np_arr -# return np_arr - - # Process PCD point cloud directly def read_ply(pcdfile): diff --git a/anomaly/gmm-change-detection/scripts/gmm/visualization.py b/anomaly/gmm-change-detection/scripts/gmm/visualization.py index fe448f74..60bab3bc 100644 --- a/anomaly/gmm-change-detection/scripts/gmm/visualization.py +++ b/anomaly/gmm-change-detection/scripts/gmm/visualization.py @@ -1,3 +1,22 @@ +#!/usr/bin/env python +# Copyright (c) 2017, United States Government, as represented by the +# Administrator of the National Aeronautics and Space Administration. +# +# All rights reserved. +# +# The "ISAAC - Integrated System for Autonomous and Adaptive Caretaking +# platform" software is 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. + # Based on the GMM visualization code: # https://github.com/sitzikbs/gmm_tutorial/blob/master/visualization.py # with modifications to accomodate using the model data