This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
import sys | |
# change this as you see fit | |
#image_path = sys.argv[1] | |
image_path = 'teste2.jpg' | |
# read in the image_data | |
image_data = tf.gfile.FastGFile(image_path, 'rb').read() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
python retrain.py --bottleneck_dir=tf_files/bottlenecks --how_many_training_steps 4000 --model_dir=tf_files/inception --output_graph=tf_files/retrained_graph.pb --output_labels=tf_files/retrained_labels.txt --image_dir tf_files/images |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
context = {} | |
ERROR_THRESHOLD = 0.25 | |
def classify(sentence): | |
results = model.predict([bow(sentence, words)])[0] | |
results = [[i,r] for i,r in enumerate(results) if r>ERROR_THRESHOLD] | |
results.sort(key=lambda x: x[1], reverse=True) | |
return_list = [] | |
for r in results: | |
return_list.append((classes[r[0]], r[1])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def clean_up_sentence(sentence): | |
# tokenizando frases | |
sentence_words = nltk.word_tokenize(sentence) | |
# stem | |
sentence_words = [stemmer.stem(word.lower()) for word in sentence_words] | |
return sentence_words | |
def bow(sentence, words, show_details=False): | |
sentence_words = clean_up_sentence(sentence) | |
bag = [0]*len(words) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# NLP | |
import nltk | |
from nltk.stem.lancaster import LancasterStemmer | |
stemmer = LancasterStemmer() | |
# importando bibliotecas | |
import numpy as np | |
import tflearn | |
import tensorflow as tf | |
import random |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def clean_up_sentence(sentence): | |
# tokenize the pattern | |
sentence_words = nltk.word_tokenize(sentence) | |
# stem each word | |
sentence_words = [stemmer.stem(word.lower()) for word in sentence_words] | |
return sentence_words | |
# return bag of words array: 0 or 1 for each word in the bag that exists in the sentence | |
def bow(sentence, words, show_details=False): | |
# tokenize the pattern |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# save all of our data structures | |
import pickle | |
pickle.dump( {'words':words, 'classes':classes, 'train_x':train_x, 'train_y':train_y}, open( "training_data", "wb" ) ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# reset underlying graph data | |
tf.reset_default_graph() | |
# Build neural network | |
net = tflearn.input_data(shape=[None, len(train_x[0])]) | |
net = tflearn.fully_connected(net, 8) | |
net = tflearn.fully_connected(net, 8) | |
net = tflearn.fully_connected(net, len(train_y[0]), activation='softmax') | |
net = tflearn.regression(net) | |
# Define model and setup tensorboard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create our training data | |
training = [] | |
output = [] | |
# create an empty array for our output | |
output_empty = [0] * len(classes) | |
# training set, bag of words for each sentence | |
for doc in documents: | |
# initialize our bag of words | |
bag = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
words = [] | |
classes = [] | |
documents = [] | |
ignore_words = ['?'] | |
# loop through each sentence in our intents patterns | |
for intent in intents['intents']: | |
for pattern in intent['patterns']: | |
# tokenize each word in the sentence | |
w = nltk.word_tokenize(pattern) | |
# add to our words list |
NewerOlder