mattfarley

Untitled

Jul 29th, 2018
365
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. #
  4. # Usage:
  5. #
  6. if [[ $# == 0 ]] ; then
  7.  
  8.     echo
  9.     echo
  10.     echo "Usage:   $(basename $0) <room> <action> option"
  11.     echo
  12.     echo "Example: $(basename $0) boys_room test clean|messy"
  13.     echo "         $(basename $0) boys_room train"
  14.     echo "         $(basename $0) boys_room score [image.jpg]"
  15.     echo
  16.     exit 0
  17.  
  18. fi
  19.  
  20. #
  21. # Model selection
  22. #
  23.  
  24. # InceptionV3
  25. # Most accurate, but also slowest
  26. MODEL_NAME=inceptionv3
  27. INPUT_HEIGHT=""
  28. INPUT_WIDTH=""
  29. TFHUB_MODULE=https://tfhub.dev/google/imagenet/inception_v3/feature_vector/1
  30.  
  31. # 224px 100% MobileNetV2 = 1.102s
  32. # This model seems accurate and fast
  33. #MODEL_NAME=mobilenetv2_224_100
  34. #INPUT_HEIGHT="--input_height=224"
  35. #INPUT_WIDTH="--input_width=224"
  36. #TFHUB_MODULE=https://tfhub.dev/google/imagenet/mobilenet_v2_100_224/feature_vector/1
  37.  
  38. # 96px 35% MobileNetV2
  39. # This model wasn't very accurate when I didn't have too much training data
  40. #MODEL_NAME=mobilenetv2_96_035
  41. #INPUT_HEIGHT="--input_height=96"
  42. #INPUT_WIDTH="--input_width=96"
  43. #TFHUB_MODULE=https://tfhub.dev/google/imagenet/mobilenet_v2_035_96/feature_vector/2
  44.  
  45. #
  46. # Config
  47. #
  48. ROOT=/b/tf
  49. cd $ROOT
  50. MODEL_ROOM=$1
  51. MODEL_ROOT=$ROOT/models/$MODEL_ROOM
  52. DATA_TEST=$ROOT/data_testing/$MODEL_ROOM
  53. DATA_TRAIN=$ROOT/data_training/$MODEL_ROOM
  54. MODEL=$MODEL_ROOT/$MODEL_NAME
  55.  
  56. #
  57. # Train a new model
  58. #
  59. if [[ $2 == "train" ]] ; then
  60.  
  61.     python retrain.py --image_dir $DATA_TRAIN --output_graph=$MODEL.pb --output_labels=$MODEL.txt --tfhub_module $TFHUB_MODULE
  62.     exit 0
  63.  
  64. fi
  65.  
  66. #
  67. # Test a URL or file
  68. #
  69. if [[ $2 == "score" ]] ; then
  70.  
  71.     # Determine if they specified a URL or a local image
  72.     #regex='(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]'
  73.     #if [[ $3 =~ $regex ]]; then
  74.  
  75.     # If they didn't specify a path-to-url, download from webcam:
  76.     if [[ $# -eq 2 ]]; then
  77.  
  78.         #
  79.         # Specified a URL, get it to tmp
  80.         #
  81.         if [[ $1 == "boys_room" ]]; then
  82.             URL=http://192.168.1.21/snapshot.cgi
  83.         fi
  84.  
  85.         if [[ $1 == "kitchen" ]]; then
  86.             URL=http://192.168.1.23/snapshot.cgi
  87.         fi
  88.  
  89.         if [[ $1 == "upstairs" ]]; then
  90.             URL=http://192.168.1.25/snapshot.cgi
  91.         fi
  92.  
  93.         TMP_IMAGE=/tmp/how_clean_$MODEL_ROOM.jpg
  94.  
  95.         # Repeat in case camera failed with zero length / bad image
  96.         wget "$URL" -O $TMP_IMAGE > /dev/null 2>&1
  97.         FILESIZE=$(stat -c%s "$TMP_IMAGE")
  98.         if [ $FILESIZE -lt 50 ]; then
  99.             sleep 2
  100.             wget "$URL" -O $TMP_IMAGE > /dev/null 2>&1
  101.         fi
  102.         if [ $FILESIZE -lt 50 ]; then
  103.             sleep 2
  104.             wget "$URL" -O $TMP_IMAGE > /dev/null 2>&1
  105.         fi
  106.         if [ $FILESIZE -lt 50 ]; then
  107.             sleep 2
  108.             wget "$URL" -O $TMP_IMAGE > /dev/null 2>&1
  109.         fi
  110.         if [ $FILESIZE -lt 50 ]; then
  111.             sleep 2
  112.             wget "$URL" -O $TMP_IMAGE > /dev/null 2>&1
  113.         fi
  114.         if [ $FILESIZE -lt 50 ]; then
  115.             sleep 2
  116.             wget "$URL" -O $TMP_IMAGE > /dev/null 2>&1
  117.         fi
  118.  
  119.     else
  120.  
  121.         # User specified a path-to-image in arg #3
  122.         TMP_IMAGE=$3
  123.  
  124.     fi
  125.  
  126.     #
  127.     # This outputs how "clean" the room is on a scale of 1..100
  128.     #
  129.     { python label_image.py --graph=$MODEL.pb --labels=$MODEL.txt $INPUT_WIDTH $INPUT_HEIGHT --input_layer=Placeholder --output_layer=final_result --image=$TMP_IMAGE; } 2>&1 | grep "clean" | cut -d ' ' -f2 | awk '{printf "%.0f\n", $1*100}'
  130.  
  131.     exit 0
  132. fi
  133.  
  134. #
  135. # Loop through 12 images help back for testing:
  136. #
  137. if [[ $2 == "test" ]] ; then
  138.     for i in {1..12}
  139.         do
  140.             { time python label_image.py --graph=$MODEL.pb --labels=$MODEL.txt $INPUT_WIDTH $INPUT_HEIGHT --input_layer=Placeholder --output_layer=final_result --image=$DATA_TEST/$3/$i.jpg; } 2>&1 | grep "$3\|real"
  141.             echo ---
  142.         done
  143.     exit 0
  144. fi
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×