|
#! /usr/bin/env bash |
|
|
|
function image_classifier() { |
|
abcli_image_classifier $@ |
|
} |
|
|
|
function abcli_image_classifier() { |
|
local task=$(abcli_unpack_keyword "$1" help) |
|
|
|
if [ "$task" == "help" ] ; then |
|
abcli_help_line "$abcli_cli_name image_classifier describe object_1" \ |
|
"describe model object_1." |
|
abcli_help_line "$abcli_cli_name image_classifier install" \ |
|
"install image_classifier." |
|
abcli_help_line "$abcli_cli_name image_classifier predict object_1 object_2" \ |
|
"run image_classifier model object_1 predict on data object_2." |
|
abcli_help_line "$abcli_cli_name image_classifier save name_1 object_1 [force]" \ |
|
"[force] save image_classifier in object_1 as name_1." |
|
abcli_help_line "$abcli_cli_name image_classifier train object_1" \ |
|
"train image_classifier on data object_1." |
|
|
|
if [ "$(abcli_keyword_is $2 verbose)" == true ] ; then |
|
python3 -m fashion_mnist.image_classifier --help |
|
fi |
|
return |
|
fi |
|
|
|
if [[ $(type -t abcli_image_classifier_$task) == "function" ]] ; then |
|
abcli_image_classifier_$task ${@:2} |
|
return |
|
fi |
|
|
|
if [ "$task" == "describe" ] ; then |
|
local model_object_name="$2" |
|
|
|
abcli_download $model_object_name |
|
|
|
python3 -m image_classifier \ |
|
describe \ |
|
--model_path $abcli_object_root/$model_object_name \ |
|
${@:3} |
|
|
|
return |
|
fi |
|
|
|
if [ "$task" == "install" ] ; then |
|
conda install -y -c anaconda seaborn |
|
return |
|
fi |
|
|
|
if [ "$task" == "release" ] ; then |
|
local model_name=$(abcli_clarify_arg "$2" image-classifier) |
|
|
|
abcli_huggingface release image-classifier $model_name ${@:3} |
|
return |
|
fi |
|
|
|
abcli_log_error "-fashion_mnist: image-classifier: $task: command not found." |
|
} |
|
|
|
function abcli_image_classifier_predict() { |
|
local model_object=$(abcli_clarify_object "$1") |
|
local data_object=$(abcli_clarify_object "$2") |
|
|
|
abcli_download object $model_object |
|
abcli_download object $data_object |
|
|
|
abcli_log "image_classifier($model_object).predict($data_object)" |
|
|
|
if [ ! -f "$abcli_object_root/$data_object/test_images.pyndarray" ] ; then |
|
python3 -m image_classifier \ |
|
preprocess \ |
|
--infer_annotation 0 \ |
|
--model_path $abcli_object_root/$model_object \ |
|
--objects $abcli_object_root/$data_object \ |
|
--output_path $abcli_object_root/$data_object \ |
|
--purpose predict \ |
|
${@:3} |
|
fi |
|
|
|
cp -v ../$data_object/*.pyndarray . |
|
cp -v ../$model_object/image_classifier/model/class_names.json . |
|
|
|
python3 -m image_classifier \ |
|
predict \ |
|
--data_path $abcli_object_root/$data_object \ |
|
--model_path $abcli_object_root/$model_object \ |
|
--output_path $abcli_object_path \ |
|
${@:4} |
|
|
|
abcli_tag set . image_classifier,predict |
|
} |
|
|
|
function abcli_image_classifier_train() { |
|
local data_object=$(abcli_clarify_object "$1" $abcli_object_name) |
|
|
|
abcli_download object $data_object |
|
|
|
local options=$2 |
|
local do_color=$(abcli_option_int "$options" "color" 0) |
|
local do_convnet=$(abcli_option_int "$options" "convnet" 0) |
|
local do_validate=$(abcli_option_int "$options" "validate" 0) |
|
|
|
local extra_args="" |
|
if [ "$do_validate" == 1 ] ; then |
|
local extra_args="--epochs 2" |
|
fi |
|
|
|
abcli_log "image_classifier.train($data_object): $options" |
|
|
|
python3 -m image_classifier \ |
|
train \ |
|
--color $do_color \ |
|
--convnet $do_convnet \ |
|
--data_path $abcli_object_root/$data_object \ |
|
--model_path $abcli_object_path \ |
|
$extra_args \ |
|
${@:3} |
|
|
|
abcli_tag set . image_classifier,train |
|
} |