0

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)
Nick ODell
  • 15,465
  • 3
  • 32
  • 66
Sneha Roy
  • 81
  • 1
  • 3
  • 16
  • What's the model you're using? I cannot seem to find any papers explictly using "Vgg Unet". – Farhood ET Apr 19 '20 at 17:14
  • @FarhoodET I am using VGG16 UNET model. – Sneha Roy Apr 19 '20 at 17:44
  • According to this your output should be 388 * 388 for each image, and if flatten it will be 150444 pixels for each image. https://towardsdatascience.com/medical-image-segmentation-part-1-unet-convolutional-networks-with-interactive-code-70f0f17f46c6 – Farhood ET Apr 19 '20 at 17:59

0 Answers0