forked from rohitmenon86/gpd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuse_gpd.sh
More file actions
executable file
·163 lines (146 loc) · 4.25 KB
/
use_gpd.sh
File metadata and controls
executable file
·163 lines (146 loc) · 4.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/bin/bash
# Simple wrapper script to use GPD from outside Docker
# This script starts the Docker container if needed and runs the external client
# Get the directory of this script
SCRIPT_DIR=$(dirname "$(readlink -f "$0")")
cd "$SCRIPT_DIR"
# Docker container name
CONTAINER_NAME="gpd_container"
# Check if Docker is running
if ! docker info >/dev/null 2>&1; then
echo "Error: Docker is not running or you don't have permission to use Docker."
echo "Please start Docker and make sure you have the necessary permissions."
exit 1
fi
# Check if the container is already running
if ! docker ps -q --filter "name=$CONTAINER_NAME" | grep -q .; then
echo "GPD Docker container is not running. Starting it now..."
# Check if container exists but is stopped
if docker ps -aq --filter "name=$CONTAINER_NAME" | grep -q .; then
echo "Container exists but is stopped. Starting it..."
docker start $CONTAINER_NAME
else
echo "Container does not exist. Creating and starting it..."
# Start the container with our run_docker_new.sh script
./run_docker_new.sh
fi
# Wait for the service to start
echo "Waiting for GPD service to start (this may take a few seconds)..."
sleep 10
else
echo "GPD Docker container is already running."
fi
# Check if Python is available
if ! command -v python >/dev/null 2>&1; then
if command -v python3 >/dev/null 2>&1; then
PYTHON_CMD="python3"
else
echo "Error: Neither python nor python3 command found."
exit 1
fi
else
PYTHON_CMD="python"
fi
# Check if requests module is available
$PYTHON_CMD -c "import requests" 2>/dev/null || {
echo "Python requests module not found. Attempting to install it..."
pip install requests || pip3 install requests || {
echo "Failed to install requests module. Please install it manually:"
echo "pip install requests"
exit 1
}
}
# Default values
ITEM_CLOUD="item_cloud.pcd"
ENV_CLOUD="env_cloud.pcd"
SERVER_URL="http://localhost:5000/predict"
ROT_RES=24
TOP_N=3
N_BEST=3
# Parse command line arguments
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
--item)
ITEM_CLOUD="$2"
shift
shift
;;
--env)
ENV_CLOUD="$2"
shift
shift
;;
--server)
SERVER_URL="$2"
shift
shift
;;
--rot_res)
ROT_RES="$2"
shift
shift
;;
--top_n)
TOP_N="$2"
shift
shift
;;
--n_best)
N_BEST="$2"
shift
shift
;;
--json)
JSON_OUTPUT="--json"
shift
;;
*)
echo "Unknown option: $key"
echo "Usage: $0 [--item ITEM_CLOUD] [--env ENV_CLOUD] [--server SERVER_URL] [--rot_res ROT_RES] [--top_n TOP_N] [--n_best N_BEST] [--json]"
exit 1
;;
esac
done
# Make the path absolute if relative
if [[ ! "$ITEM_CLOUD" = /* ]]; then
ITEM_CLOUD="$SCRIPT_DIR/$ITEM_CLOUD"
fi
if [[ ! "$ENV_CLOUD" = /* ]]; then
ENV_CLOUD="$SCRIPT_DIR/$ENV_CLOUD"
fi
# Check if the point cloud files exist
if [ ! -f "$ITEM_CLOUD" ]; then
echo "Error: Item cloud file not found: $ITEM_CLOUD"
exit 1
fi
if [ ! -f "$ENV_CLOUD" ]; then
echo "Error: Environment cloud file not found: $ENV_CLOUD"
exit 1
fi
echo "Using the following parameters:"
echo " Item cloud: $ITEM_CLOUD"
echo " Environment cloud: $ENV_CLOUD"
echo " Server URL: $SERVER_URL"
echo " Rotation resolution: $ROT_RES"
echo " Top N: $TOP_N"
echo " N best: $N_BEST"
if [ ! -z "$JSON_OUTPUT" ]; then
echo " Output format: JSON"
fi
# Run the external client
echo "Calling GPD service..."
$PYTHON_CMD gpd_external_client.py \
--item "$ITEM_CLOUD" \
--env "$ENV_CLOUD" \
--server "$SERVER_URL" \
--rot_res "$ROT_RES" \
--top_n "$TOP_N" \
--n_best "$N_BEST" \
$JSON_OUTPUT
# Print help message
echo
echo "You can use this script with different parameters:"
echo " ./use_gpd.sh --item path/to/item.pcd --env path/to/env.pcd"
echo " ./use_gpd.sh --rot_res 12 --n_best 5"
echo " ./use_gpd.sh --json # to get JSON output"