Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c43aff
commit a69db50
Showing
23 changed files
with
748 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ results/ | |
temp/ | ||
runner/ | ||
temporary/ | ||
test/data-models/ | ||
test/data-temp/ | ||
*.db | ||
|
||
# PyCharm | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
dist: xenial | ||
sudo: required | ||
language: python | ||
python: | ||
- '3.5' | ||
- '3.6' | ||
- '3.7' | ||
install: | ||
- pip install -r requirements.txt | ||
- pip install pytest | ||
script: | ||
- mkdir tests/data-models | ||
- mkdir tests/data-temp | ||
- wget /tests/data-models/ https://github.com/OlafenwaMoses/ImageAI/releases/download/1.0/DenseNet-BC-121-32.h5 | ||
- wget /tests/data-models/ https://github.com/OlafenwaMoses/ImageAI/releases/download/1.0/inception_v3_weights_tf_dim_ordering_tf_kernels.h5 | ||
- wget /tests/data-models/ https://github.com/OlafenwaMoses/ImageAI/releases/download/1.0/resnet50_weights_tf_dim_ordering_tf_kernels.h5 | ||
- wget /tests/data-models/ https://github.com/OlafenwaMoses/ImageAI/releases/download/1.0/squeezenet_weights_tf_dim_ordering_tf_kernels.h5 | ||
- wget /tests/data-models/ https://github.com/OlafenwaMoses/ImageAI/releases/download/1.0/resnet50_coco_best_v2.0.1.h5 | ||
- wget /tests/data-models/ https://github.com/OlafenwaMoses/ImageAI/releases/download/1.0/yolo.h5 | ||
- wget /tests/data-models/ https://github.com/OlafenwaMoses/ImageAI/releases/download/1.0/yolo-tiny.h5 | ||
- python setup.py | ||
- cd test | ||
- pytest | ||
|
||
|
||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
tensorflow | ||
keras | ||
numpy | ||
Pillow | ||
pillow | ||
scipy | ||
h5py | ||
matplotlib | ||
|
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"9" : "waiter", | ||
"6" : "mechanic", | ||
"2" : "engineer", | ||
"4" : "fireman", | ||
"0" : "chef", | ||
"5" : "judge", | ||
"7" : "pilot", | ||
"8" : "police", | ||
"3" : "farmer", | ||
"1" : "doctor" | ||
} |
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
from imageai.Prediction.Custom import CustomImagePrediction | ||
import os | ||
import pytest | ||
from os.path import dirname | ||
|
||
|
||
main_folder = os.getcwd() | ||
|
||
all_images = os.listdir(os.path.join(main_folder, "data-images")) | ||
all_images_array = [] | ||
|
||
|
||
def images_to_image_array(): | ||
for image in all_images: | ||
all_images_array.append(os.path.join(main_folder, "data-images", image)) | ||
|
||
|
||
|
||
@pytest.mark.resnet | ||
@pytest.mark.recognition_custom | ||
def test_custom_recognition_model_resnet(): | ||
predictor = CustomImagePrediction() | ||
predictor.setModelTypeAsResNet() | ||
predictor.setModelPath(os.path.join(main_folder, "data-models", "idenprof_resnet.h5")) | ||
predictor.setJsonPath(model_json=os.path.join(main_folder, "data-json", "idenprof.json")) | ||
predictor.loadModel(num_objects=10) | ||
predictions, probabilities = predictor.predictImage(image_input=os.path.join(main_folder, main_folder, "data-images", "9.jpg")) | ||
|
||
assert isinstance(predictions, list) | ||
assert isinstance(probabilities, list) | ||
assert isinstance(predictions[0], str) | ||
assert isinstance(probabilities[0], str) | ||
|
||
|
||
@pytest.mark.resnet | ||
@pytest.mark.recognition_custom | ||
def test_custom_recognition_full_model_resnet(): | ||
predictor = CustomImagePrediction() | ||
predictor.setModelPath(os.path.join(main_folder, "data-models", "idenprof_full_resnet_ex-001_acc-0.119792.h5")) | ||
predictor.setJsonPath(model_json=os.path.join(main_folder, "data-json", "idenprof.json")) | ||
predictor.loadFullModel(num_objects=10) | ||
predictions, probabilities = predictor.predictImage(image_input=os.path.join(main_folder, main_folder, "data-images", "9.jpg")) | ||
|
||
assert isinstance(predictions, list) | ||
assert isinstance(probabilities, list) | ||
assert isinstance(predictions[0], str) | ||
assert isinstance(probabilities[0], str) | ||
|
||
|
||
@pytest.mark.densenet | ||
@pytest.mark.recognition_custom | ||
def test_custom_recognition_model_densenet(): | ||
predictor = CustomImagePrediction() | ||
predictor.setModelTypeAsDenseNet() | ||
predictor.setModelPath(os.path.join(main_folder, "data-models", "idenprof_densenet-0.763500.h5")) | ||
predictor.setJsonPath(model_json=os.path.join(main_folder, "data-json", "idenprof.json")) | ||
predictor.loadModel(num_objects=10) | ||
predictions, probabilities = predictor.predictImage(image_input=os.path.join(main_folder, main_folder, "data-images", "9.jpg")) | ||
|
||
assert isinstance(predictions, list) | ||
assert isinstance(probabilities, list) | ||
assert isinstance(predictions[0], str) | ||
assert isinstance(probabilities[0], str) | ||
|
||
|
||
|
||
|
||
@pytest.mark.resnet | ||
@pytest.mark.recognition_custom | ||
@pytest.mark.recognition_multi | ||
def test_custom_recognition_model_resnet_multi(): | ||
predictor = CustomImagePrediction() | ||
predictor.setModelTypeAsResNet() | ||
predictor.setModelPath(os.path.join(main_folder, "data-models", "idenprof_resnet.h5")) | ||
predictor.setJsonPath(model_json=os.path.join(main_folder, "data-json", "idenprof.json")) | ||
predictor.loadModel(num_objects=10) | ||
images_to_image_array() | ||
result_array = predictor.predictMultipleImages(sent_images_array=all_images_array) | ||
|
||
assert isinstance(result_array, list) | ||
for result in result_array: | ||
assert "predictions" in result | ||
assert "percentage_probabilities" in result | ||
assert isinstance(result["predictions"], list) | ||
assert isinstance(result["percentage_probabilities"], list) | ||
assert isinstance(result["predictions"][0], str) | ||
assert isinstance(result["percentage_probabilities"][0], str) | ||
|
||
|
||
@pytest.mark.resnet | ||
@pytest.mark.recognition_custom | ||
@pytest.mark.recognition_multi | ||
def test_custom_recognition_full_model_resnet_multi(): | ||
predictor = CustomImagePrediction() | ||
predictor.setModelPath(os.path.join(main_folder, "data-models", "idenprof_full_resnet_ex-001_acc-0.119792.h5")) | ||
predictor.setJsonPath(model_json=os.path.join(main_folder, "data-json", "idenprof.json")) | ||
predictor.loadFullModel(num_objects=10) | ||
images_to_image_array() | ||
result_array = predictor.predictMultipleImages(sent_images_array=all_images_array) | ||
|
||
assert isinstance(result_array, list) | ||
for result in result_array: | ||
assert "predictions" in result | ||
assert "percentage_probabilities" in result | ||
assert isinstance(result["predictions"], list) | ||
assert isinstance(result["percentage_probabilities"], list) | ||
assert isinstance(result["predictions"][0], str) | ||
assert isinstance(result["percentage_probabilities"][0], str) | ||
|
||
|
||
@pytest.mark.densenet | ||
@pytest.mark.recognition_custom | ||
@pytest.mark.recognition_multi | ||
def test_custom_recognition_model_densenet_multi(): | ||
predictor = CustomImagePrediction() | ||
predictor.setModelTypeAsDenseNet() | ||
predictor.setModelPath(os.path.join(main_folder, "data-models", "idenprof_densenet-0.763500.h5")) | ||
predictor.setJsonPath(model_json=os.path.join(main_folder, "data-json", "idenprof.json")) | ||
predictor.loadModel(num_objects=10) | ||
images_to_image_array() | ||
result_array = predictor.predictMultipleImages(sent_images_array=all_images_array) | ||
|
||
assert isinstance(result_array, list) | ||
for result in result_array: | ||
assert "predictions" in result | ||
assert "percentage_probabilities" in result | ||
assert isinstance(result["predictions"], list) | ||
assert isinstance(result["percentage_probabilities"], list) | ||
assert isinstance(result["predictions"][0], str) | ||
assert isinstance(result["percentage_probabilities"][0], str) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
from imageai.Prediction import ImagePrediction | ||
import os | ||
import cv2 | ||
import pytest | ||
from os.path import dirname | ||
# wget /data-models/ model_file.h5 | ||
|
||
main_folder = os.getcwd() | ||
|
||
@pytest.mark.squeezenet | ||
@pytest.mark.recognition | ||
def test_recognition_model_squeezenet(): | ||
|
||
print("TOP FOLDER: ", main_folder) | ||
predictor = ImagePrediction() | ||
predictor.setModelTypeAsSqueezeNet() | ||
predictor.setModelPath(os.path.join(main_folder, "data-models", "squeezenet_weights_tf_dim_ordering_tf_kernels.h5")) | ||
predictor.loadModel() | ||
predictions, probabilities = predictor.predictImage(image_input=os.path.join(main_folder, main_folder, "data-images", "1.jpg")) | ||
|
||
assert isinstance(predictions, list) | ||
assert isinstance(probabilities, list) | ||
assert isinstance(predictions[0], str) | ||
assert isinstance(probabilities[0], float) | ||
|
||
@pytest.mark.resnet | ||
@pytest.mark.recognition | ||
def test_recognition_model_resnet(): | ||
predictor = ImagePrediction() | ||
predictor.setModelTypeAsResNet() | ||
predictor.setModelPath(os.path.join(main_folder, "data-models", "resnet50_weights_tf_dim_ordering_tf_kernels.h5")) | ||
predictor.loadModel() | ||
predictions, probabilities = predictor.predictImage(image_input=os.path.join(main_folder, main_folder, "data-images", "1.jpg")) | ||
|
||
assert isinstance(predictions, list) | ||
assert isinstance(probabilities, list) | ||
assert isinstance(predictions[0], str) | ||
assert isinstance(probabilities[0], float) | ||
|
||
@pytest.mark.inceptionv3 | ||
@pytest.mark.recognition | ||
def test_recognition_model_inceptionv3(): | ||
predictor = ImagePrediction() | ||
predictor.setModelTypeAsInceptionV3() | ||
predictor.setModelPath(os.path.join(main_folder, "data-models", "inception_v3_weights_tf_dim_ordering_tf_kernels.h5")) | ||
predictor.loadModel() | ||
predictions, probabilities = predictor.predictImage(image_input=os.path.join(main_folder, main_folder, "data-images", "1.jpg")) | ||
|
||
assert isinstance(predictions, list) | ||
assert isinstance(probabilities, list) | ||
assert isinstance(predictions[0], str) | ||
assert isinstance(probabilities[0], float) | ||
|
||
@pytest.mark.densenet | ||
@pytest.mark.recognition | ||
def test_recognition_model_densenet(): | ||
predictor = ImagePrediction() | ||
predictor.setModelTypeAsDenseNet() | ||
predictor.setModelPath(os.path.join(main_folder, "data-models", "DenseNet-BC-121-32.h5")) | ||
predictor.loadModel() | ||
predictions, probabilities = predictor.predictImage(image_input=os.path.join(main_folder, main_folder, "data-images", "1.jpg")) | ||
|
||
assert isinstance(predictions, list) | ||
assert isinstance(probabilities, list) | ||
assert isinstance(predictions[0], str) | ||
assert isinstance(probabilities[0], float) | ||
|
||
|
||
@pytest.mark.squeezenet | ||
@pytest.mark.recognition | ||
def test_recognition_model_squeezenet_array_input(): | ||
|
||
|
||
predictor = ImagePrediction() | ||
predictor.setModelTypeAsSqueezeNet() | ||
predictor.setModelPath(os.path.join(main_folder, "data-models", "squeezenet_weights_tf_dim_ordering_tf_kernels.h5")) | ||
predictor.loadModel() | ||
image_array = cv2.imread(os.path.join(main_folder, main_folder, "data-images", "1.jpg")) | ||
predictions, probabilities = predictor.predictImage(image_input=image_array, input_type="array") | ||
|
||
assert isinstance(predictions, list) | ||
assert isinstance(probabilities, list) | ||
assert isinstance(predictions[0], str) | ||
assert isinstance(probabilities[0], float) | ||
|
||
@pytest.mark.resnet | ||
@pytest.mark.recognition | ||
def test_recognition_model_resnet_array_input(): | ||
predictor = ImagePrediction() | ||
predictor.setModelTypeAsResNet() | ||
predictor.setModelPath(os.path.join(main_folder, "data-models", "resnet50_weights_tf_dim_ordering_tf_kernels.h5")) | ||
predictor.loadModel() | ||
image_array = cv2.imread(os.path.join(main_folder, main_folder, "data-images", "1.jpg")) | ||
predictions, probabilities = predictor.predictImage(image_input=image_array, input_type="array") | ||
|
||
assert isinstance(predictions, list) | ||
assert isinstance(probabilities, list) | ||
assert isinstance(predictions[0], str) | ||
assert isinstance(probabilities[0], float) | ||
|
||
@pytest.mark.inceptionv3 | ||
@pytest.mark.recognition | ||
def test_recognition_model_inceptionv3_array_input(): | ||
predictor = ImagePrediction() | ||
predictor.setModelTypeAsInceptionV3() | ||
predictor.setModelPath(os.path.join(main_folder, "data-models", "inception_v3_weights_tf_dim_ordering_tf_kernels.h5")) | ||
predictor.loadModel() | ||
image_array = cv2.imread(os.path.join(main_folder, main_folder, "data-images", "1.jpg")) | ||
predictions, probabilities = predictor.predictImage(image_input=image_array, input_type="array") | ||
|
||
assert isinstance(predictions, list) | ||
assert isinstance(probabilities, list) | ||
assert isinstance(predictions[0], str) | ||
assert isinstance(probabilities[0], float) | ||
|
||
@pytest.mark.densenet | ||
@pytest.mark.recognition | ||
def test_recognition_model_densenet_array_input(): | ||
predictor = ImagePrediction() | ||
predictor.setModelTypeAsDenseNet() | ||
predictor.setModelPath(os.path.join(main_folder, "data-models", "DenseNet-BC-121-32.h5")) | ||
predictor.loadModel() | ||
image_array = cv2.imread(os.path.join(main_folder, main_folder, "data-images", "1.jpg")) | ||
predictions, probabilities = predictor.predictImage(image_input=image_array, input_type="array") | ||
|
||
assert isinstance(predictions, list) | ||
assert isinstance(probabilities, list) | ||
assert isinstance(predictions[0], str) | ||
assert isinstance(probabilities[0], float) | ||
|
||
test_recognition_model_squeezenet() |
Oops, something went wrong.