home/exp1000/acquire_and_label_images.py
def label_image(self, image_filename, model_tflite_filename, labels_filename, image_height, image_width, image_mean, image_std):
        """Label an image using the image classifier with the given model and labels files."""

        try:
            # Build the image labeling command.
            cmd_label_image = '{P} {I} {M} {L} {height} {width} {mean} {std}'.format(\
                P=IMAGE_CLASSIFIER_BIN_PATH,\
                I=image_filename,\
                M=model_tflite_filename,\
                L=labels_filename,\
                height=image_height,\
                width=image_width,\
                mean=image_mean,\
                std=image_std)

            # Log the command that will be executed.
            logger.info("Running command to label the image: {C}".format(C=cmd_label_image))

            # Create a subprocess to execute the image classification program.
            process = subprocess.Popen(cmd_label_image, stdout=subprocess.PIPE, shell=True)

            # Get program stdout.
            predictions = (process.communicate()[0]).decode("utf-8")

            return_code = process.returncode 

            # Get program return code.
            if return_code == 0:
                # Log results.
                logger.info("Model prediction results: " + predictions)

                # The program's stdout is prediction result as a JSON object string.
                return json.loads(predictions)
            
            else: 
                # Log error code if image classification program returned and error code.
                logger.error("The image classification program returned error code {E}.".format(E=str(return_code)))

        except:
            # Log the exception.
            logger.exception("An error was thrown while attempting to run the image classification program.")

        return None
Label an image using the image classifier with the given model and labels files.
Label an image using the image classifier with the given model and labels files.
Label an image using the image classifier with the given model and labels files .
def label_image(self, image_filename, model_tflite_filename, labels_filename, image_height, image_width, image_mean, image_std):
        try:
            cmd_label_image = '{P} {I} {M} {L} {height} {width} {mean} {std}'.format(\
                P=IMAGE_CLASSIFIER_BIN_PATH,\
                I=image_filename,\
                M=model_tflite_filename,\
                L=labels_filename,\
                height=image_height,\
                width=image_width,\
                mean=image_mean,\
                std=image_std)
            logger.info("Running command to label the image: {C}".format(C=cmd_label_image))
            process = subprocess.Popen(cmd_label_image, stdout=subprocess.PIPE, shell=True)
            predictions = (process.communicate()[0]).decode("utf-8")
            return_code = process.returncode 
            if return_code == 0:
                logger.info("Model prediction results: " + predictions)
                return json.loads(predictions)
            else: 
                logger.error("The image classification program returned error code {E}.".format(E=str(return_code)))
        except:
            logger.exception("An error was thrown while attempting to run the image classification program.")
        return None
def label_image ( self , image_filename , model_tflite_filename , labels_filename , image_height , image_width , image_mean , image_std ) : try : cmd_label_image = '{P} {I} {M} {L} {height} {width} {mean} {std}' . format ( P = IMAGE_CLASSIFIER_BIN_PATH , I = image_filename , M = model_tflite_filename , L = labels_filename , height = image_height , width = image_width , mean = image_mean , std = image_std ) logger . info ( "Running command to label the image: {C}" . format ( C = cmd_label_image ) ) process = subprocess . Popen ( cmd_label_image , stdout = subprocess . PIPE , shell = True ) predictions = ( process . communicate ( ) [ 0 ] ) . decode ( "utf-8" ) return_code = process . returncode if return_code == 0 : logger . info ( "Model prediction results: " + predictions ) return json . loads ( predictions ) else : logger . error ( "The image classification program returned error code {E}." . format ( E = str ( return_code ) ) ) except : logger . exception ( "An error was thrown while attempting to run the image classification program." ) return None
Label an image using the image classifier with the given model and labels files.
Label an image using the image classifier with the given model and labels files .
"""Label an image using the image classifier with the given model and labels files.""" # Build the image labeling command. # Log the command that will be executed. # Create a subprocess to execute the image classification program. # Get program stdout. # Get program return code. # Log results. # The program's stdout is prediction result as a JSON object string. # Log error code if image classification program returned and error code. # Log the exception.
self
image_filename
model_tflite_filename
labels_filename
image_height
image_width
image_mean
image_std