I am working on training an object detection model on Google Colab based on 1. After training the model, I want to test the model on new image as in this Test the TFLite model on your image. I am obtaining an error when running the code in Run object detection and show the detection results:
INPUT_IMAGE_URL = "https://storage.googleapis.com/cloud-ml-data/img/openimage/3/2520/3916261642_0a504acd60_o.jpg"
DETECTION_THRESHOLD = 0.3
TEMP_FILE = '/tmp/image.png'
!wget -q -O $TEMP_FILE $INPUT_IMAGE_URL
im = Image.open(TEMP_FILE)
im.thumbnail((512, 512), Image.ANTIALIAS)
im.save(TEMP_FILE, 'PNG')
# Load the TFLite model
interpreter = tf.lite.Interpreter(model_path=model_path)
interpreter.allocate_tensors()
# Run inference and draw detection result on the local copy of the original file
detection_result_image = run_odt_and_draw_results(
TEMP_FILE,
interpreter,
threshold=DETECTION_THRESHOLD
)
# Show the detection result
Image.fromarray(detection_result_image)
Can someone please explain to me what is the following code part used for :
TEMP_FILE = '/tmp/image.png'
!wget -q -O $TEMP_FILE $INPUT_IMAGE_URL
im = Image.open(TEMP_FILE)
im.thumbnail((512, 512), Image.ANTIALIAS)
im.save(TEMP_FILE, 'PNG')
Thank you in advance!
CodePudding user response:
# define local path to save image
TEMP_FILE = '/tmp/image.png'
# In a notebook, run bash command to download image locally from URL
!wget -q -O $TEMP_FILE $INPUT_IMAGE_URL
# Open the image (with Pillow library most likely)
im = Image.open(TEMP_FILE)
# Resize it to 512*512 pixels with the antialiasing resampling algorithm
im.thumbnail((512, 512), Image.ANTIALIAS)
# Save output image to local file
im.save(TEMP_FILE, 'PNG')