Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds EfficientNet B0 Model to training scripts #56

Merged
merged 2 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ images/**
!images/ReadMe.md
# Ignore my Visual Studio solution for editing python
NSFWModel/**
trained_models/**
trained_models/**
training/train_best_models.cmd
11 changes: 11 additions & 0 deletions training/train_all_models.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,21 @@
:: https://tfhub.dev/google/imagenet/resnet_v2_50/classification/4
:: https://tfhub.dev/google/imagenet/inception_v3/classification/4
:: https://tfhub.dev/google/imagenet/nasnet_mobile/classification/4
:: https://tfhub.dev/tensorflow/efficientnet/b0/classification/1
::
:: If you get CUDA_OUT_OF_MEMORY crash, you need to pass --batch_size NUMBER, reducing until you don't get this error.
:: It is advised by Google not to have a batch size < 8.

:: Train EfficientNet B0
python make_nsfw_model.py --image_dir %cd%\..\images --image_size 224 --saved_model_dir %cd%\..\trained_models\efficientnet_b0_224 --labels_output_file %cd%\..\trained_models\efficientnet_b0_224\class_labels.txt --tfhub_module https://tfhub.dev/tensorflow/efficientnet/b0/classification/1 --tflite_output_file %cd%\..\trained_models\efficientnet_b0_224\saved_model.tflite --train_epochs 5 --batch_size 16 --do_fine_tuning --learning_rate 0.05 --dropout_rate 0.0 --momentum 0.9
:: Note that installing tensorflowjs also installs tensorflow-cpu A.K.A. bye-bye-training.
:: tensorflowjs_converter --input_format=tf_saved_model --output_format=tfjs_graph_model --signature_name=serving_default --saved_model_tags=serve %cd%\..\trained_models\efficientnet_b0_224 %cd%\..\trained_models\efficientnet_b0_224\web_model
:: Or, for a quantized (1 byte) version
:: tensorflowjs_converter --input_format=tf_saved_model --output_format=tfjs_graph_model --signature_name=serving_default --saved_model_tags=serve %cd%\..\trained_models\efficientnet_b0_224 %cd%\..\trained_models\efficientnet_b0_224\web_model_quantized --quantization_bytes 1

:: Wait for Python/CUDA/GPU to recover. Seems to die without this.
Timeout /T 60 /Nobreak

:: Train Mobilenet V2 140
python make_nsfw_model.py --image_dir %cd%\..\images --image_size 224 --saved_model_dir %cd%\..\trained_models\mobilenet_v2_140_224 --labels_output_file %cd%\..\trained_models\mobilenet_v2_140_224\class_labels.txt --tfhub_module https://tfhub.dev/google/imagenet/mobilenet_v2_140_224/classification/4 --tflite_output_file %cd%\..\trained_models\mobilenet_v2_140_224\saved_model.tflite --train_epochs 5 --batch_size 32 --do_fine_tuning --learning_rate 0.001 --dropout_rate 0.0 --momentum 0.9
:: Note that installing tensorflowjs also installs tensorflow-cpu A.K.A. bye-bye-training.
Expand Down
11 changes: 11 additions & 0 deletions training/train_all_models.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,21 @@
# https://tfhub.dev/google/imagenet/resnet_v2_50/classification/4
# https://tfhub.dev/google/imagenet/inception_v3/classification/4
# https://tfhub.dev/google/imagenet/nasnet_mobile/classification/4
# https://tfhub.dev/tensorflow/efficientnet/b0/classification/1
#
# If you get CUDA_OUT_OF_MEMORY crash, you need to pass --batch_size NUMBER, reducing until you don't get this error.
# It is advised by Google not to have a batch size < 8.

# Train EfficientNet B0
python3 make_nsfw_model.py --image_dir $PWD/../images --image_size 224 --saved_model_dir $PWD/../trained_models/efficientnet_b0_224 --labels_output_file $PWD/../trained_models/efficientnet_b0_224/class_labels.txt --tfhub_module https://tfhub.dev/tensorflow/efficientnet/b0/classification/1 --tflite_output_file $PWD/../trained_models/efficientnet_b0_224/saved_model.tflite --train_epochs 5 --batch_size 16 --do_fine_tuning --learning_rate 0.05 --dropout_rate 0.0 --momentum 0.9
# Note that installing tensorflowjs also installs tensorflow-cpu A.K.A. bye-bye-training.
# tensorflowjs_converter --input_format=tf_saved_model --output_format=tfjs_graph_model --signature_name=serving_default --saved_model_tags=serve $PWD/../trained_models/efficientnet_b0_224 $PWD/../trained_models/efficientnet_b0_224/web_model
# Or, for a quantized (1 byte) version
# tensorflowjs_converter --input_format=tf_saved_model --output_format=tfjs_graph_model --signature_name=serving_default --saved_model_tags=serve $PWD/../trained_models/efficientnet_b0_224 $PWD/../trained_models/efficientnet_b0_224/web_model_quantized --quantization_bytes 1

# Wait for Python/CUDA/GPU to recover. Seems to die without this.
sleep 60

# Train Mobilenet V2 140
python3 make_nsfw_model.py --image_dir $PWD/../images --image_size 224 --saved_model_dir $PWD/../trained_models/mobilenet_v2_140_224 --labels_output_file $PWD/../trained_models/mobilenet_v2_140_224/class_labels.txt --tfhub_module https://tfhub.dev/google/imagenet/mobilenet_v2_140_224/classification/4 --tflite_output_file $PWD/../trained_models/mobilenet_v2_140_224/saved_model.tflite --train_epochs 5 --batch_size 32 --do_fine_tuning --learning_rate 0.001 --dropout_rate 0.0 --momentum 0.9
# Note that installing tensorflowjs also installs tensorflow-cpu A.K.A. bye-bye-training.
Expand Down