prepare_dataset.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. #!/bin/bash
  15. set -e
  16. DATASET_NAME=${1:-'ml-20m'}
  17. RAW_DATADIR=${2:-'/data'}
  18. CACHED_DATADIR=${3:-"${RAW_DATADIR}/cache/${DATASET_NAME}"}
  19. # you can add another option to this case in order to support other datasets
  20. case ${DATASET_NAME} in
  21. 'ml-20m')
  22. ZIP_PATH=${RAW_DATADIR}/'ml-20m.zip'
  23. RATINGS_PATH=${RAW_DATADIR}'/ml-20m/ratings.csv'
  24. ;;
  25. 'ml-1m')
  26. ZIP_PATH=${RAW_DATADIR}/'ml-1m.zip'
  27. RATINGS_PATH=${RAW_DATADIR}'/ml-1m/ratings.dat'
  28. ;;
  29. *)
  30. echo "Unsupported dataset name: $DATASET_NAME"
  31. exit 1
  32. esac
  33. if [ ! -d ${RAW_DATADIR} ]; then
  34. mkdir -p ${RAW_DATADIR}
  35. fi
  36. if [ ! -d ${CACHED_DATADIR} ]; then
  37. mkdir -p ${CACHED_DATADIR}
  38. fi
  39. rm -f log
  40. if [ ! -f ${ZIP_PATH} ]; then
  41. echo "Dataset not found!"
  42. echo "To continue please download the dataset from http://files.grouplens.org/datasets/movielens/ml-20m.zip \\
  43. put it in ${ZIP_PATH} and rerun this script"
  44. exit 1
  45. fi
  46. if [ ! -f ${RATINGS_PATH} ]; then
  47. unzip -u ${ZIP_PATH} -d ${RAW_DATADIR}
  48. fi
  49. if [ ! -f ${CACHED_DATADIR}/train_ratings.pickle ]; then
  50. echo "preprocessing ${RATINGS_PATH} and save to disk"
  51. t0=$(date +%s)
  52. python convert.py --path ${RATINGS_PATH} --output ${CACHED_DATADIR}
  53. t1=$(date +%s)
  54. delta=$(( $t1 - $t0 ))
  55. echo "Finish preprocessing in $delta seconds"
  56. else
  57. echo 'Using cached preprocessed data'
  58. fi
  59. echo "Dataset $DATASET_NAME successfully prepared at: $CACHED_DATADIR"