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

missing predict.py #29

Open
linksyncjameshwartlopez opened this issue Jan 26, 2018 · 6 comments
Open

missing predict.py #29

linksyncjameshwartlopez opened this issue Jan 26, 2018 · 6 comments

Comments

@linksyncjameshwartlopez

I wonder where is predict.py file that was mention in https://www.youtube.com/watch?v=u9FPqkuoEJ8 at 6:41 of the video

@hcchengithub
Copy link

hcchengithub commented Jan 26, 2018

There's none such file. But it can be done manually:

model.load(pathname) 
y, sr = librosa.load("PathName.wav",mono=True)
mfcc = librosa.feature.mfcc(y,sr) 
MFCC = np.pad(mfcc,((0,0),(0,80-len(mfcc[0]))),mode='constant',constant_values=0) 
model.predict([MFCC]) 

https://github.com/hcchengithub/tensorflow_speech_recognition_demo

@linksyncjameshwartlopez
Copy link
Author

linksyncjameshwartlopez commented Jan 26, 2018

Should it be something like this. Im only guessing because I don't how to build up model variable. kindly correct me if im wrong.

`from future import division, print_function, absolute_import
import tflearn
import speech_data
import tensorflow as tf

learning_rate = 0.0001
training_iters = 300000 # steps
batch_size = 64

width = 20 # mfcc features
height = 80 # (max) length of utterance
classes = 10 # digits

batch = word_batch = speech_data.mfcc_batch_generator(batch_size)
X, Y = next(batch)
trainX, trainY = X, Y
testX, testY = X, Y #overfit for now

net = tflearn.input_data([None, width, height])
net = tflearn.lstm(net, 128, dropout=0.8)
net = tflearn.fully_connected(net, classes, activation='softmax')
net = tflearn.regression(net, optimizer='adam', learning_rate=learning_rate, loss='categorical_crossentropy')

col = tf.get_collection(tf.GraphKeys.TRAINABLE_VARIABLES)
for x in col:
tf.add_to_collection(tf.GraphKeys.VARIABLES, x )

model = tflearn.DNN(net, tensorboard_verbose=0)
model.load(pathname)
y, sr = librosa.load("PathName.wav",mono=True)
mfcc = librosa.feature.mfcc(y,sr)
MFCC = np.pad(mfcc,((0,0),(0,80-len(mfcc[0]))),mode='constant',constant_values=0)
model.predict([MFCC])`

@hcchengithub
Copy link

hcchengithub commented Jan 26, 2018

No, you need to know how to use tflearn's model.save() and model.load() to save-restore your trained networks. You need to complete training your model, get the saved network so you don't need to do the training every time when you only want to try some predicts. They are not difficult. Just do it correctly and you can make it. My snippet assumes that you have the saved network already and start from there shows you how to do the prediction.

@linksyncjameshwartlopez
Copy link
Author

linksyncjameshwartlopez commented Jan 31, 2018

Thanks @hcchengithub , one last question how do you instantiate model variable in your code snippet? I've tried to look at it and i arrive on this https://stackoverflow.com/questions/45099608/tflearn-issue-over-model-load?answertab=active#tab-top.

Or am i doing it wrong. Im so naive that i don't know how to load previously saved model of tflearn. Hope you can help me with this :). i'll try to dig more if i can find answers myself, it seems to be so obvious to the person who already done loading of a saved model but for a person who haven't done it yet is really vague.

@hcchengithub
Copy link

This demo is not really suitable for totally new comers. It's uncompleted ,incorrect and useless, really.
Don't waste your time here.
For general AI learning, I suggest http://www.hvass-labs.org/ or Google developers Josh Gordon's {Machine Learning} Recipes
For speech recognition, jump to Mozilla DeepSpeech.

@mohsin671
Copy link

Hi @hcchengithub , were you able to run the code? I am having this error:
ValueError: At least two variables have the same name: FullyConnected/W

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

No branches or pull requests

3 participants