Cntk: Scoring grayscale images

Created on 16 Feb 2017  路  8Comments  路  Source: microsoft/CNTK

To score new images and print the probability of the class being 1 (it's a binary classifier), I've written this code:

def eval_mri(model, image_path):
    mri = Image.open(image_path)
#    mri = mri.resize((image_width, image_height), Image.BILINEAR)
    mri = mri.resize((image_width, image_height), Image.ANTIALIAS)
    image_mean   = 32768.0
    image_data   = np.array(mri, dtype=np.float32)
    image_data  -= image_mean
    image_data = image_data/65536.0
    image_data = image_data[np.newaxis,:,:]
    image_data = np.ascontiguousarray(image_data)
    result     = np.squeeze(model.eval({model.arguments[0]:[image_data]}))
    print(image_path, result[:])
    return

data_path = 'E:/Labels'
# model dimensions
image_height = 512
image_width  = 512
num_channels = 1
num_classes  = 2

z = load_model('E:/Models/detMen-T1.dnn')
y = softmax(z)

file_path = os.path.join(data_path, 'Test-t1-meniscus.csv')
with open(file_path, 'r') as csvfile:
    reader = csv.reader(csvfile, delimiter='\t')
    for row in reader:
        image_path = row[0]
        ris = eval_mri(y, image_path )

but it always returns the same classification, [1.0 1....e-17] , even for images in the test set, where the Training Error was very low.
Images are grayscale png (0-65535), and I trained the model using the CNTK reader (so it expects a color axis). Am I doing something wrong?

bug

Most helpful comment

Any updates on this bug fix?

All 8 comments

It seems I have the same problem reported here:
https://github.com/Microsoft/CNTK/issues/1369
but I'm training using python, how can I specify grayscale=True in the Python trainer?

I tried deserializer['grayscale'] = True, suggested here:
https://github.com/Microsoft/CNTK/issues/1172
but nothing changed.

Try:

cntk.io.MinibatchSource(cntk.io.ImageDeserializer(map_file, cntk.io.StreamDefs(
        features = cntk.io.StreamDef(field='image', transforms=transforms), 
        labels   = cntk.io.StreamDef(field='label', shape=num_classes))), 
        grayscale = True, 
        randomize=is_training)

With that I get this error:
TypeError: __init__() got an unexpected keyword argument 'grayscale'
I'm using beta10.

That's a bug. We will fix it.

By the way, because my images are 16bit grayscale instead of 8bit , do you know if the issue below has been fixed in the current code: https://github.com/Microsoft/CNTK/issues/961 ?
MartIgap proposed to fix it, but I don't now if it has been done. Maybe my problem is affected by both flags that should be defined in the Reader (grayscale, and CV_LOAD_IMAGE_ANYDEPTH for opencv) .
Could you also tell me when the fix will be available?
Thanks

Any updates on this bug fix?

No update since december 2017, what is the status of this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

youssefhb picture youssefhb  路  27Comments

StevenGann picture StevenGann  路  125Comments

haryngod picture haryngod  路  17Comments

robinhad picture robinhad  路  61Comments

cha-zhang picture cha-zhang  路  49Comments