idenprof//train//chef// 900 images of chefs
idenprof//train//doctor// 900 images of doctors
idenprof//train//engineer// 900 images of engineer
idenprof//train//farmer// 900 images of farmers
idenprof//train//firefighter// 900 images of firefighters
idenprof//train//judge// 900 images of judges
idenprof//train//mechanic// 900 images of mechanics
idenprof//train//pilot// 900 images of pilots
idenprof//train//chef// 900 images of chef
idenprof//train//police// 900 images of police
idenprof//train//waiter// 900 images of waiters
idenprof//test//chef// 200 images of chefs
idenprof//test//doctor// 200 images of doctors
idenprof//test//engineer// 200 images of engineer
idenprof//test//farmer// 200 images of farmers
idenprof//test//firefighter// 200 images of firefighters
idenprof//test//judge// 200 images of judges
idenprof//test//mechanic// 200 images of mechanics
idenprof//test//pilot// 200 images of pilots
idenprof//test//chef// 200 images of chef
idenprof//test//police// 200 images of police
idenprof//test//waiter// 200 images of waiters
pip install tensorflow
pip install numpy
pip install scipy
pip install opencv-python
pip install pillow
pip install matplotlib
pip install h5py
pip install keras
pip3 install https://github.com/OlafenwaMoses/ImageAI/releases/download/2.0.2/imageai-2.0.2-py3-none-any.whl
from imageai.Prediction.Custom import ModelTraining
model_trainer = ModelTraining()
model_trainer.setModelTypeAsResNet()
model_trainer.setDataDirectory("idenprof")
model_trainer.trainModel(num_objects=10, num_experiments=200, enhance_data=True, batch_size=32, show_network_summary=True)
=====================================
Total params: 23,608,202
Trainable params: 23,555,082
Non-trainable params: 53,120
______________________________________
Using Enhanced Data Generation
Found 4000 images belonging to 4 classes.
Found 800 images belonging to 4 classes.
JSON Mapping for the model classes saved to C:\Users\User\PycharmProjects\FirstTraining\idenprof\json\model_class.json
Number of experiments (Epochs) : 200
Epoch 1/100
1/280 [>.............................] - ETA: 52s - loss: 2.3026 - acc: 0.2500
2/280 [>.............................] - ETA: 52s - loss: 2.3026 - acc: 0.2500
3/280 [>.............................] - ETA: 52s - loss: 2.3026 - acc: 0.2500
..............................,
..............................,
..............................,
279/280 [===========================>..] - ETA: 1s - loss: 2.3097 - acc: 0.0625Epoch 00000: saving model to C:\Users\User\PycharmProjects\FirstTraining\idenprof\models\model_ex-000_acc-0.100000.h5
280/280 [==============================] - 51s - loss: 2.3095 - acc: 0.0600 - val_loss: 2.3026 - val_acc: 0.1000
from imageai.Prediction.Custom import CustomImagePrediction
import os
execution_path = os.getcwd()
prediction = CustomImagePrediction()
prediction.setModelTypeAsResNet()
prediction.setModelPath("idenprof_061-0.7933.h5")
prediction.setJsonPath("idenprof_model_class.json")
prediction.loadModel(num_objects=10)
predictions, probabilities = prediction.predictImage("image.jpg", result_count=3)
for eachPrediction, eachProbability in zip(predictions, probabilities):
print(eachPrediction , " : " , eachProbability)
waiter : 99.99997615814209
chef : 1.568847380895022e-05
judge : 1.0255866556008186e-05
欢迎光临 智客公社 (http://bbs.cnaiplus.com/) | Powered by Discuz! X3.4 |