jakeret / tf_unet

Generic U-Net Tensorflow implementation for image segmentation
GNU General Public License v3.0
1.9k stars 748 forks source link

'str' object has no attribute 'shape' #222

Closed abderhasan closed 5 years ago

abderhasan commented 5 years ago

Hello,

I'm trying to run this script on my grayscale images:

from tf_unet import unet, util, image_util

output_path = '/home/me/Desktop/tf_unet/results' data = '/home/me/Desktop/tf_unet/predict'

preparing data loading

data_provider = image_util.ImageDataProvider('/home/me/Desktop/tf_unet/images/train/*.jpg', data_suffix='_data.jpg',mask_suffix='_gt.jpg')

setup & training

net = unet.Unet(layers=3, features_root=64, channels=1, n_class=2) trainer = unet.Trainer(net) path = trainer.train(data_provider, output_path, training_iters=1, epochs=1)

verification

prediction = net.predict(path, data)

unet.error_rate(prediction, util.crop_to_shape(label, prediction.shape))

img = util.combine_img_prediction(data, label, prediction) util.save_image(img, "prediction.jpg")

But, getting the following error:

prediction = net.predict(path, data) File "/home/me/Desktop/tf_unet/tf_unet/unet.py", line 276, in predict y_dummy = np.empty((x_test.shape[0], x_test.shape[1], x_test.shape[2], self.n_class)) AttributeError: 'str' object has no attribute 'shape'

How can I solve this issue?

Thanks.

jakeret commented 5 years ago

The predict function is expecting a tensor not a filepath

abderhasan commented 5 years ago

Thanks for your kind reply. It worked when I did the following:

test_images = np.array([cv2.imread(fname, 1) for fname in filelist])

As per #173 .

Gumballing commented 5 years ago

@abderhasan hello I have the same error as you. What is the correct command to load the test image as data? Thank you.