Edit dpu_resnet50

Hi everyone

I’m currently trying to edit this notebook.

I didn’t edit anything except the 8th cell. I would like to print something if the image shows a certain animal.

def run(image_index, display=False):
    preprocessed = preprocess_fn(cv2.imread(
        os.path.join(image_folder, original_images[image_index])))
    image[0,...] = preprocessed.reshape(shapeIn[1:])
    job_id = dpu.execute_async(input_data, output_data)
    dpu.wait(job_id)
    temp = [j.reshape(1, outputSize) for j in output_data]
    softmax = calculate_softmax(temp[0][0])
    if display:
        display_image = cv2.imread(os.path.join(
            image_folder, original_images[image_index]))
        _, ax = plt.subplots(1)
        _ = ax.imshow(cv2.cvtColor(display_image, cv2.COLOR_BGR2RGB))
        #print("Classification: {}".format(predict_label(softmax)))
        #print(f"{softmax}, {predict_label(softmax)}")
        print(type(predict_label(softmax)))
        temp_variable = predict_label(softmax)
        if temp_variable == "Arctic fox, white fox, Alopex lagopus":
            print("hey")
        elif predict_label(softmax) == "Arctic fox, white fox, Alopex lagopus":
            print("It definitely should work")
        else:
            print(f"{temp_variable} is the temporary variable")
            print(f"{predict_label(softmax)} should be in the temporary variable")
            print("error")
            
        print("hello_world")
        temp_variable2 = "this temp variable"
        print(type(temp_variable2))
        if temp_variable2 == "this temp variable":
            print("It should work")

I added a couple of tests to see whether or not I was going in the right direction.

I got this:

<class 'str'>
Arctic fox, white fox, Alopex lagopus
 is the temporary variable
Arctic fox, white fox, Alopex lagopus

error
hello_world
<class 'str'>
It should work

I thought that since predict_label(softmax) returns a variable I could use it in a conditional statement. What is wrong in my code?

Thanks in advance for your answer.

Make sure whether the returned string has a line ending ‘\n’

Hi

Why did you mention “\n”?

This function returns something from this file.