[AI] Python3 uses TF-Hub for transfer learning (image classification)

machine environment

  • win10
  • python3.6

Install dependencies

  • pip install tensorflow==1.7.0
  • pip install tensorflow-hub

Github address


Prepare picture material

  • Note: Each category must have at least 100 pictures, otherwise an error will be reported
  • Put the pictures into categories and put them in the photos folder

Train the model (default is to use Inception V3)

  • Clear the output folder first
  • 20 steps of training here
python .\retrain.py --image_dir .\photos\ --saved_model_dir .\mod
el\ --bottleneck_dir .\bottleneck\ --how_many_training_steps 20 --output_labels .\output\output_labels.txt --output_grap
h .\output\retrain.pb

Test the model (test a single image)

python .\label_image.py --graph .\output\retrain.pb --labels .\o
utput\output_labels.txt --input_layer=Placeholder --output_layer=final_result --image .\test.jpg

Remark

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325992403&siteId=291194637