-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtensorflow_file_search.sh
executable file
·54 lines (46 loc) · 1.08 KB
/
tensorflow_file_search.sh
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
#!/bin/bash
TF_MODEL_FILE_EXT=".pb"
TF_MODEL_CKPT_EXT=".ckpt"
function is_tensorflow_dir {
contents=($(ls "$1"))
assets="assets"
variables="variables"
if [[ " ${contents[*]} " =~ " ${assets} " ]] ; then
if [[ " ${contents[*]} " =~ " ${variables} " ]] ; then # (($contents[(Ie)$variables])) ; then
for i in $contents; do
if [[ "$i"=="model.pb" ]] ; then
return 0
fi
done
return 1
else
return 1
fi
else
return 1
fi
}
SEARCH_DIR=$1
STAGING_DIR=$2
matches=()
# Find Tensorflow directories (based on signature)
for f in $SEARCH_DIR/**/* ; do
if [[ -d "$f" ]] ; then
if is_tensorflow_dir $f; then
for g in $(realpath $f)/* ; do
matches+=$(realpath $g)
done
fi
fi
done
# Find Tensorflow checkpoint (.ckpt) files
ckpt_files=$(find $SEARCH_DIR -name "*$TF_MODEL_CKPT_EXT*" -type f -not -path '*/\.*' 2>/dev/null)
matches+=$ckpt_files
# Stage files
if [ ${#matches[@]} -ne 0 ] ; then
mkdir -p $STAGING_DIR
for m in $matches; do
cp -r $m $STAGING_DIR 2>/dev/null;
done
fi
echo $STAGING_DIR