headlines icon indicating copy to clipboard operation
headlines copied to clipboard

Prediction is not working

Open BenjamWhite opened this issue 7 years ago • 13 comments

I'm running the same code on test data and get strange weights back.

import h5py
with h5py.File('data/%s.hdf5'%FN1, mode='r') as f:
    if 'layer_names' not in f.attrs and 'model_weights' in f:
        f = f['model_weights']
    weights = [np.copy(v) for v in f['timedistributed_1'].itervalues()]

and map(lambda x: x.shape, weights) is giving me back: [(2,)]

Also run the code with Keras 2.0.0 and the actual version. Can it be due to different versions?

Thanks in advance!

BenjamWhite avatar Jun 05 '17 06:06 BenjamWhite

@BenjamWhite i am trying to fix this problem from two days. please help me if you find it too..

imranshaikmuma avatar Jun 05 '17 06:06 imranshaikmuma

I thought first it might be something with theano and tensorflow as they store data in different order, but changing channel_first to channel_last didn't help.

BenjamWhite avatar Jun 05 '17 06:06 BenjamWhite

what i feel is file is not having weights of 'time_distributed_1' layer. i googled and find nothing on this. it has only [array(['bias:0', 'kernel:0'], dtype='<U8')] inside.

imranshaikmuma avatar Jun 05 '17 06:06 imranshaikmuma

well, that's a different issue, when TimeDistributed gets defined, there is a ), missing before name. So it assigns the name to the Dense method. Before:

model.add(TimeDistributed(Dense(vocab_size,
                                kernel_regularizer=regularizer, 
                                bias_regularizer=regularizer, name = 'timedistributed_1')))

After:

model.add(TimeDistributed(Dense(vocab_size,
                                kernel_regularizer=regularizer, 
                                bias_regularizer=regularizer),
                                name = 'timedistributed_1'))

There is also a method to show the content of the h5py.

Haha, that's the next error I'm getting with those values [array(['bias:0', 'kernel:0'], dtype='<U8')] the

# out very own softmax
def output2probs(output):
    print 'output:', type(output), output
    print 'weights[0]:', type(weights[0]), weights[0]
    #print 'weights[1]:', type(weights[1])
    output = np.dot(output, weights[0]) + weights[1]
    output -= output.max()
    output = np.exp(output)
    output /= output.sum()
    return output

is saying it doesn't know dtype='<U8'

BenjamWhite avatar Jun 05 '17 06:06 BenjamWhite

weights[0] and weights[1] should be an array of weights. we are not getting that from our trained model file. if you can solve this, everything will be automatically solved

imranshaikmuma avatar Jun 05 '17 07:06 imranshaikmuma

check this link it helped me a lot (Cell 94) https://github.com/rtlee9/recipe-summarization/blob/master/src/predict.ipynb here when we are using fit_generator, weights are produced till dropout3 only. and there is no layer for time distributed..everyone has the same problem but they ignored and moved on..

imranshaikmuma avatar Jun 05 '17 08:06 imranshaikmuma

where you able to run this?

BenjamWhite avatar Jun 05 '17 08:06 BenjamWhite

i am able to run but i am not getting the desired output. i am using a different data like job description and generating a job title my data is huge and i am looking for gpu to train the model what about you?

imranshaikmuma avatar Jun 20 '17 16:06 imranshaikmuma

didn't really work on it anymore (had no time so far), so basically still the same error. how did you get around that error before?

What is the diff between expected and real output? Is it a data problem?

BenjamWhite avatar Jun 21 '17 06:06 BenjamWhite

If you open the hdf5 file you should see the file structure. For me, I had to modify it to

import h5py
with h5py.File('data/%s.hdf5'%FN1, mode='r') as f:
    if 'layer_names' not in f.attrs and 'model_weights' in f:
        f = f['model_weights']
    weights = [np.copy(v) for v in f['time_distributed_1']['time_distributed_1'].values()]
weights = np.array([weights[1], weights[0]])

elainelinlin avatar May 27 '18 06:05 elainelinlin

@elainelinlin did you get any prediction out of it? For your own data?

nauman-akram avatar Jun 10 '18 14:06 nauman-akram

@fzr2009 Yes. What is not working for you?

elainelinlin avatar Jun 11 '18 05:06 elainelinlin

@elainelinlin I get this KeyError every time with different string in it, Please help if you can 34963263_1255056604597058_1311645615918153728_n

nauman-akram avatar Jun 11 '18 05:06 nauman-akram