MCPcopy Index your code
hub / github.com/TensorPy/TensorPy / classify_local_image

Function classify_local_image

tensorpy/image_base.py:109–126  ·  view source on GitHub ↗

Classify an image from a local file path.

(file_path)

Source from the content-addressed store, hash-verified

107
108
109def classify_local_image(file_path):
110 """ Classify an image from a local file path. """
111 if not file_path.endswith('.jpg') and not file_path.endswith('.png'):
112 raise Exception("Expecting a .jpg or .png file!")
113 downloads_folder = settings.DOWNLOADS_FOLDER
114 hex_name = 'temp_image_%s' % uuid.uuid4().hex
115 hex_name_png = hex_name + '.png'
116 hex_name_jpg = hex_name + '.jpg'
117 shutil.copy2(file_path, os.path.join(downloads_folder, hex_name_png))
118 convert_image_file_to_jpg(
119 "%s/%s" % (downloads_folder, hex_name_png))
120 os.rename(downloads_folder + "/" + hex_name_png,
121 downloads_folder + "/temp_image_png.png")
122 best_guess = classify_image.external_run(
123 "%s/%s" % (downloads_folder, hex_name_jpg))
124 os.rename(downloads_folder + "/" + hex_name_jpg,
125 downloads_folder + "/temp_image_jpg.jpg")
126 return best_guess
127
128
129def classify_folder_images(folder_path, return_dict=False):

Callers 2

classify_folder_imagesFunction · 0.85
classifyFunction · 0.85

Calls 1

Tested by

no test coverage detected