prediction.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. '''Created Aug 15, 2021 deeejas'''
  2. import os
  3. # import tensorflow as tf
  4. # gpus = tf.config.list_physical_devices('GPU')
  5. # tf.config.experimental.set_virtual_device_configuration(
  6. # gpus[0],
  7. # [tf.config.experimental.VirtualDeviceConfiguration(memory_limit=1024)]
  8. # )
  9. # gpus = tf.config.experimental.list_physical_devices('GPU')
  10. # if gpus:
  11. # try:
  12. # # Currently, memory growth needs to be the same across GPUs
  13. # for gpu in gpus:
  14. # tf.config.experimental.set_memory_growth(gpu, True)
  15. # logical_gpus = tf.config.experimental.list_logical_devices('GPU')
  16. # print(len(gpus), "Physical GPUs,", len(logical_gpus), "Logical GPUs")
  17. # except RuntimeError as e:
  18. # # Memory growth must be set before GPUs have been initialized
  19. # print(e)
  20. from imageai.Classification import ImageClassification
  21. execution_path = os.getcwd()
  22. prediction = ImageClassification()
  23. prediction.setModelTypeAsMobileNetV2()
  24. prediction.setModelPath(os.path.join(execution_path, "mobilenet_v2.h5"))
  25. prediction.loadModel()
  26. predictions, probabilities = prediction.classifyImage(os.path.join(execution_path, "circuit_board_img_result.png"), result_count=5)
  27. for eachPrediction, eachProbability in zip(predictions, probabilities):
  28. print(eachPrediction, ": ", eachProbability)