Kalpana
Kalpana

Reputation: 123

I tried simple can & dog image classification in tensorflow and suddenly mess with problem. please could you please help me to solve this?

I got following error when exciting this function, error: OpenCV(4.5.2) C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-1bq9o88m\opencv\modules\imgproc\src\resize.cpp:4051: error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize

for img in os.listdir(folder):
    img_path = os.path.join(folder, img)
    img_arr  = cv2.resize(cv2.imread(img_path), (IMG_SIZE, IMG_SIZE))

Upvotes: 0

Views: 75

Answers (2)

Kalpana
Kalpana

Reputation: 123

I realized the issue there. In here some images are broken, so resizing failed to run. I used following function to pass the broken images,

        try:
            img_array = cv2.imread(os.path.join(path,img) ,cv2.IMREAD_GRAYSCALE) 
            new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE)) 
            training_data.append([new_array, class_num]) 
        except Exception as e:  # in the interest in keeping the output clean...
            pass

Thank you for your help!!!

Upvotes: 0

Gerry P
Gerry P

Reputation: 8102

What is the shape of you input images and what are the minimum and maximum pixel values. It appears cv2.imread is not reading the image. Try using debug code below:

for img in os.listdir(folder):
    img_path = os.path.join(folder, img)
    print (img_path)
    try:
        input_img=cv2.imread(img_path)
        img_shape=input_img.shape
        print ( img_shape)
    except:
        print(' image was not read in')
   

Upvotes: 1

Related Questions