| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
if [ "$#" -ne 2 ]; then |
| 4 |
echo "This script copies an imglab XML file and its associated images to a new folder." |
| 5 |
echo "Notably, it will avoid copying unnecessary images." |
| 6 |
echo "Call this script like this:" |
| 7 |
echo " ./copy_dataset some_file.xml dest_dir" |
| 8 |
exit 1 |
| 9 |
fi |
| 10 |
|
| 11 |
XML_FILE=$1 |
| 12 |
DEST=$2 |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
mkdir -p $DEST |
| 17 |
|
| 18 |
# Get the list of files we need to copy, then build the cp statements with 1000 files at most in each statement, then tell bash to run them all. |
| 19 |
imglab --files $XML_FILE | xargs perl -e 'use File::Spec; foreach (@ARGV) {print File::Spec->abs2rel($_) . "\n"}' | sort | uniq | xargs -L1000 echo | xargs -I{} echo cp -a --parents {} $DEST | bash |
| 20 |
|
| 21 |
convert_imglab_paths_to_relative $XML_FILE > $DEST/$(basename $XML_FILE) |
| 22 |
|