I have trained vgg_unet model in my own dataset and save the model as model.h5. After saving the model I am loading the model using from keras.models import load_model
. Now when I am trying to predict and save the result as image using the code given below it gives me and error: OpenCV(4.1.2) /io/opencv/modules/imgcodecs/src/loadsave.cpp:668: error: (-215:Assertion failed) image.channels() == 1 || image.channels() == 3 || image.channels() == 4 in function 'imwrite_'
. I want output as an image. The shape of the output array is (1, 102400, 256). Please suggest me something about how to save that numpy array as image.
The code for the prediction is given below:
inp="drive/My Drive/CT Scan Segmentation/dataset/test_img/test9.jpeg"
img = cv2.imread(inp)
img_pred = image.load_img('drive/My Drive/CT Scan Segmentation/dataset/test_img/test9.jpeg', target_size = (640, 640))
img_pred = image.img_to_array(img_pred)
img_pred = np.expand_dims(img_pred, axis = 0)
out = model.predict(img_pred)
cv2.imwrite("drive/My Drive/CT Scan Segmentation/dataset/test_mask/test9.png", out)