#NoPayJan Offer - Access all CloudxLab Courses for free between 1st to 31st JanEnroll Now >>
We have already discussed that we developed the project How to Deploy an Image Classification Model using Flask.
Here, we shall measure the amount of time taken to execute that project.
time python filename.pyin the console, we could see the time of execution for the file
Switch to the
Image-Classification-App folder using
Activate the virtual environment using
Create a file named
test_client_without_zmq.py. If you have not deleted the environment from How to Deploy an Image Classification Model using Flask project, this file will already be there. You can delete it first using
And change the vi to insert mode by pressing 'a' or 'i'
Copy-paste the following code in
test_client_without_zmq.py and save it using
ESC followed by
from tensorflow.keras.applications.resnet50 import ResNet50 as myModel from tensorflow.keras.applications.resnet50 import preprocess_input, decode_predictions from tensorflow.keras.preprocessing import image import numpy as np model = myModel(weights="imagenet") def get_classes(file_path): img = image.load_img(file_path, target_size=(224, 224)) x = image.img_to_array(img) x= np.array([x]) x = preprocess_input(x) preds = model.predict(x) predictions = decode_predictions(preds, top=3) print(predictions) return predictions if __name__ == "__main__": name = '/cxldata/projects/image-class/dog.png' get_classes(name)
We are doing this to understand how much execution time it is taking for the model to load and predict the classes. In the above code, we are importing the model and feeding an image as input to the model to get its predictions.
test_client_without_zmq.py file with the
time command as follows:
time python test_client_without_zmq.py
You can run any program with time to measure how much time the command is taking. Here we are running "python test_client_without_zmq.py" with "time". It displays something like this:
real 0m9.606s user 0m10.621s sys 0m2.090s
Observe the time displayed against "real" that is the time we are going focus on. In our case, the time is 9.606 seconds.
Run the same file for several times with different images. Some images are already in the
image-class folder. You may view the file names using
ls /cxldata/projects/image-class command. Observe the amount of time taken to execute the program for different images.
Also run the
Now go to your favorite browser (preferably Google Chrome), and go to http://f.cloudxlab.com:4100/.
We could observe that, for classification, the amount of time taken is at least around 10-21 seconds.
No hints are availble for this assesment
Answer is not availble for this assesment
Note - Having trouble with the assessment engine? Follow the steps listed here