Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can not predict images by already trained model #273

Open
kxhaaa opened this issue Jun 7, 2019 · 2 comments
Open

can not predict images by already trained model #273

kxhaaa opened this issue Jun 7, 2019 · 2 comments
Labels

Comments

@kxhaaa
Copy link

kxhaaa commented Jun 7, 2019

i have already trained a model and get a good prediction image.

but when i try to load the model and predict other images, i find the results of prediction images are all black.

if i run this code, the result is good :

data, y_test = data_provider(3)

prediction = net.predict(trainpath, data)

print("Testing error rate: {:.2f}%".format(unet.error_rate(prediction,
                                                               util.crop_to_shape(y_test, prediction.shape))))

unet.error_rate(prediction, util.crop_to_shape(y_test, prediction.shape))
img = util.combine_img_prediction(data, y_test, prediction)
util.save_image(img, "prediction.jpg")

and if i use the code, the result is almost black (cell_1.tif is one of the training images):

from tf_unet import unet, util
import numpy as np

import cv2

model_path = 'd:/NET/predict/model.ckpt'

net = unet.Unet(layers=3, features_root=64, channels=1, n_class=2)

image_path=("d:/NET/data/cell_1.tif")
data = np.reshape(a=cv2.imread(image_path, flags=0), newshape=(1, 400,400, 1))
prediction = net.predict(model_path, data)
prediction=util.to_rgb(prediction[..., 1].reshape(-1, prediction.shape[2], 1))
util.save_image(prediction, "d:/NET/predict/cell_1.tif")
@jakeret
Copy link
Owner

jakeret commented Jul 11, 2019

it's probably a bit late, but the reason for this behaviour might be because the images are not preprocessed as the ones used for training (e.g. scaling to [0,1), removing outliers, etc)

@kxhaaa
Copy link
Author

kxhaaa commented Jul 15, 2019

it's probably a bit late, but the reason for this behaviour might be because the images are not preprocessed as the ones used for training (e.g. scaling to [0,1), removing outliers, etc)

thanks for your reply. and in fact, currently i just use image_util.ImageDataProvider with a '0' label to load the image, though it looks like a little 'lazy',o( ̄▽ ̄)ブ.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants