- run sh setup_tf_pi.sh (installs tensorflow)
- run sh ImageClassificationRetraining.sh (runs the test image retraining code, you can check the progress at 0.0.0.0:6006)
Last active
February 27, 2018 20:54
-
-
Save sjain07/a2fc03cae9e9f061846c86d6e5a6af5b to your computer and use it in GitHub Desktop.
RaspberryPiTensorFlow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM tensorflow/tensorflow:1.5.0-gpu | |
RUN apt-get update && apt-get install -y --no-install-recommends \ | |
python-pip \ | |
protobuf-compiler \ | |
python-pil \ | |
python-lxml \ | |
python-numpy \ | |
python-scipy \ | |
python-dev \ | |
python-pip \ | |
python-nose \ | |
g++ \ | |
libopenblas-dev \ | |
git \ | |
python-tk \ | |
wget \ | |
nano | |
RUN pip --no-cache-dir install \ | |
lxml \ | |
jupyter \ | |
matplotlib \ | |
pillow \ | |
Cython \ | |
h5py | |
RUN ldconfig | |
WORKDIR / | |
RUN mkdir tensorflow | |
WORKDIR tensorflow | |
RUN git clone https://github.com/tensorflow/models.git | |
WORKDIR models/research/ | |
RUN protoc object_detection/protos/*.proto --python_out=. | |
WORKDIR / | |
RUN curl https://gist.githubusercontent.com/sjain07/a2fc03cae9e9f061846c86d6e5a6af5b/raw/7c4ad9632b8780126e850573fe10afccea96555d/tf_object_detection.sh > run_object_detection_training.sh | |
ENTRYPOINT sh run_object_detection_training.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git clone https://github.com/googlecodelabs/tensorflow-for-poets-2 | |
cd tensorflow-for-poets-2 | |
curl http://download.tensorflow.org/example_images/flower_photos.tgz | tar xz -C tf_files | |
ls tf_files/flower_photos | |
IMAGE_SIZE=224 | |
ARCHITECTURE="mobilenet_0.50_${IMAGE_SIZE}" | |
tensorboard --logdir tf_files/training_summaries & | |
python -m scripts.retrain \ | |
--bottleneck_dir=tf_files/bottlenecks \ | |
--how_many_training_steps=500 \ | |
--model_dir=tf_files/models/ \ | |
--summaries_dir=tf_files/training_summaries/"${ARCHITECTURE}" \ | |
--output_graph=tf_files/retrained_graph.pb \ | |
--output_labels=tf_files/retrained_labels.txt \ | |
--architecture="${ARCHITECTURE}" \ | |
--image_dir=tf_files/flower_photos | |
python -m scripts.label_image \ | |
--graph=tf_files/retrained_graph.pb \ | |
--image=tf_files/flower_photos/daisy/21652746_cc379e0eea_m.jpg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
sudo apt-get update | |
sudo apt-get install -y nvidia-384 | |
sudo docker -v | |
if [ $? -ne 0 ]; then | |
curl -fsSL get.docker.com -o get-docker.sh && sudo sh get-docker.sh | |
fi | |
sudo nvidia-docker -v | |
if [ $? -ne 0 ]; then | |
echo "INSTALLING NVIDIA DOCKER" | |
wget -P /tmp https://github.com/NVIDIA/nvidia-docker/releases/download/v1.0.1/nvidia-docker_1.0.1-1_amd64.deb | |
sudo dpkg -i /tmp/nvidia-docker*.deb && rm /tmp/nvidia-docker*.deb | |
sudo apt-get install -y nvidia-modprobe | |
fi | |
sudo service nvidia-docker start | |
curl https://gist.githubusercontent.com/sjain07/a2fc03cae9e9f061846c86d6e5a6af5b/raw/8328fdf017ab6fa3de568f5208e0ec2262011bad/Dockerfile > Dockerfile | |
sudo nvidia-docker build -t object_detection -f Dockerfile . | |
sudo nvidia-docker run object_detection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo apt-get update | |
sudo apt-get install python-pip python-dev | |
wget https://github.com/samjabrahams/tensorflow-on-raspberry-pi/releases/download/v1.1.0/tensorflow-1.1.0-cp27-none-linux_armv7l.whl | |
sudo pip install tensorflow-1.1.0-cp27-none-linux_armv7l.whl | |
sudo pip uninstall mock | |
sudo pip install mock | |
echo 'import tensorflow as tf | |
hello = tf.constant("Hello, TensorFlow!") | |
sess = tf.Session() | |
print(sess.run(hello))' > test.py | |
python test.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# SSD with Mobilenet v1, configured for Oxford-IIIT Pets Dataset. | |
# Users should configure the fine_tune_checkpoint field in the train config as | |
# well as the label_map_path and input_path fields in the train_input_reader and | |
# eval_input_reader. Search for "PATH_TO_BE_CONFIGURED" to find the fields that | |
# should be configured. | |
model { | |
ssd { | |
num_classes: 37 | |
box_coder { | |
faster_rcnn_box_coder { | |
y_scale: 10.0 | |
x_scale: 10.0 | |
height_scale: 5.0 | |
width_scale: 5.0 | |
} | |
} | |
matcher { | |
argmax_matcher { | |
matched_threshold: 0.5 | |
unmatched_threshold: 0.5 | |
ignore_thresholds: false | |
negatives_lower_than_unmatched: true | |
force_match_for_each_row: true | |
} | |
} | |
similarity_calculator { | |
iou_similarity { | |
} | |
} | |
anchor_generator { | |
ssd_anchor_generator { | |
num_layers: 6 | |
min_scale: 0.2 | |
max_scale: 0.95 | |
aspect_ratios: 1.0 | |
aspect_ratios: 2.0 | |
aspect_ratios: 0.5 | |
aspect_ratios: 3.0 | |
aspect_ratios: 0.3333 | |
} | |
} | |
image_resizer { | |
fixed_shape_resizer { | |
height: 300 | |
width: 300 | |
} | |
} | |
box_predictor { | |
convolutional_box_predictor { | |
min_depth: 0 | |
max_depth: 0 | |
num_layers_before_predictor: 0 | |
use_dropout: false | |
dropout_keep_probability: 0.8 | |
kernel_size: 1 | |
box_code_size: 4 | |
apply_sigmoid_to_scores: false | |
conv_hyperparams { | |
activation: RELU_6, | |
regularizer { | |
l2_regularizer { | |
weight: 0.00004 | |
} | |
} | |
initializer { | |
truncated_normal_initializer { | |
stddev: 0.03 | |
mean: 0.0 | |
} | |
} | |
batch_norm { | |
train: true, | |
scale: true, | |
center: true, | |
decay: 0.9997, | |
epsilon: 0.001, | |
} | |
} | |
} | |
} | |
feature_extractor { | |
type: 'ssd_mobilenet_v1' | |
min_depth: 16 | |
depth_multiplier: 1.0 | |
conv_hyperparams { | |
activation: RELU_6, | |
regularizer { | |
l2_regularizer { | |
weight: 0.00004 | |
} | |
} | |
initializer { | |
truncated_normal_initializer { | |
stddev: 0.03 | |
mean: 0.0 | |
} | |
} | |
batch_norm { | |
train: true, | |
scale: true, | |
center: true, | |
decay: 0.9997, | |
epsilon: 0.001, | |
} | |
} | |
} | |
loss { | |
classification_loss { | |
weighted_sigmoid { | |
anchorwise_output: true | |
} | |
} | |
localization_loss { | |
weighted_smooth_l1 { | |
anchorwise_output: true | |
} | |
} | |
hard_example_miner { | |
num_hard_examples: 3000 | |
iou_threshold: 0.99 | |
loss_type: CLASSIFICATION | |
max_negatives_per_positive: 3 | |
min_negatives_per_image: 0 | |
} | |
classification_weight: 1.0 | |
localization_weight: 1.0 | |
} | |
normalize_loss_by_num_matches: true | |
post_processing { | |
batch_non_max_suppression { | |
score_threshold: 1e-8 | |
iou_threshold: 0.6 | |
max_detections_per_class: 100 | |
max_total_detections: 100 | |
} | |
score_converter: SIGMOID | |
} | |
} | |
} | |
train_config: { | |
batch_size: 24 | |
optimizer { | |
rms_prop_optimizer: { | |
learning_rate: { | |
exponential_decay_learning_rate { | |
initial_learning_rate: 0.004 | |
decay_steps: 800720 | |
decay_factor: 0.95 | |
} | |
} | |
momentum_optimizer_value: 0.9 | |
decay: 0.9 | |
epsilon: 1.0 | |
} | |
} | |
#fine_tune_checkpoint: "object_detection/ace_venture/models/model/train/model.ckpt" | |
#from_detection_checkpoint: false | |
# Note: The below line limits the training process to 200K steps, which we | |
# empirically found to be sufficient enough to train the pets dataset. This | |
# effectively bypasses the learning rate schedule (the learning rate will | |
# never decay). Remove the below line to train indefinitely. | |
num_steps: 200000 | |
data_augmentation_options { | |
random_horizontal_flip { | |
} | |
} | |
data_augmentation_options { | |
ssd_random_crop { | |
} | |
} | |
} | |
train_input_reader: { | |
tf_record_input_reader { | |
input_path: "object_detection/ace_ventura/data/pet_train_with_masks.record" | |
} | |
label_map_path: "object_detection/ace_ventura/data/pet_label_map.pbtxt" | |
} | |
eval_config: { | |
num_examples: 2000 | |
# Note: The below line limits the evaluation process to 10 evaluations. | |
# Remove the below line to evaluate indefinitely. | |
max_evals: 10 | |
} | |
eval_input_reader: { | |
tf_record_input_reader { | |
input_path: "object_detection/ace_ventura/data/pet_val_with_masks.record" | |
} | |
label_map_path: "object_detection/ace_ventura/data/pet_label_map.pbtxt" | |
shuffle: false | |
num_readers: 1 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set -e | |
cd / | |
git clone https://github.com/pdollar/coco.git | |
cd coco/PythonAPI | |
make | |
make install | |
python setup.py install | |
cd /tensorflow/models/research/ | |
export PYTHONPATH=/tensorflow/models/research/slim:$PYTHONPATH | |
python object_detection/builders/model_builder_test.py | |
wget http://www.robots.ox.ac.uk/~vgg/data/pets/data/images.tar.gz | |
wget http://www.robots.ox.ac.uk/~vgg/data/pets/data/annotations.tar.gz | |
tar -xvf images.tar.gz | |
tar -xvf annotations.tar.gz | |
python object_detection/dataset_tools/create_pet_tf_record.py \ | |
--label_map_path=object_detection/data/pet_label_map.pbtxt \ | |
--data_dir=`pwd` \ | |
--output_dir=`pwd` | |
export MODEL_DIRECTORY=ace_ventura | |
cd object_detection | |
mkdir $MODEL_DIRECTORY | |
mkdir -p $MODEL_DIRECTORY/data/ | |
mkdir -p $MODEL_DIRECTORY/models/model/train | |
mkdir -p $MODEL_DIRECTORY/models/model/eval | |
cp ./data/pet_label_map.pbtxt ./$MODEL_DIRECTORY/data/ | |
cp ../pet_train_with_masks.record ./$MODEL_DIRECTORY/data/ | |
cp ../pet_val_with_masks.record ./$MODEL_DIRECTORY/data/ | |
cd ./$MODEL_DIRECTORY/models/model/ | |
wget https://gist.githubusercontent.com/sjain07/a2fc03cae9e9f061846c86d6e5a6af5b/raw/aebc6033063fa56c2094c3d5a8a962dffbff9ee1/ssd_mobilenet_v1_pets.config | |
cd /tensorflow/models/research/ | |
perl -i -pe 's/channels=3,\n/channels=3),\n/g' object_detection/data_decoders/tf_example_decoder.py | |
perl -i -pe 's/dct_method=dct_method/\#dct_method=dct_method/g' object_detection/data_decoders/tf_example_decoder.py | |
nohup & tensorboard --logdir=train:object_detection/$MODEL_DIRECTORY/models/model/train/,eval:object_detection/$MODEL_DIRECTORY/models/model/eval/ & | |
python object_detection/train.py \ | |
--logtostderr \ | |
--pipeline_config_path=/tensorflow/models/research/object_detection/$MODEL_DIRECTORY/models/model/ssd_mobilenet_v1_pets.config \ | |
--train_dir=/tensorflow/models/research/object_detection/$MODEL_DIRECTORY/models/model/train/ | |
python object_detection/eval.py \ | |
--logtostderr \ | |
--pipeline_config_path=object_detection/$MODEL_DIRECTORY/models/model/ssd_mobilenet_v1_pets.config \ | |
--eval_dir=object_detection/$MODEL_DIRECTORY/models/model/eval/ \ | |
--checkpoint_dir=object_detection/$MODEL_DIRECTORY/models/model/train/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment