Exemple #1
0
def get_image():
    global model, lb
    img = CropIm("..\\testim\\acer_platanoides__03.jpg")
    label, prob = Classify(img, model, lb)
    print("success")
    result = label.replace("_", " ")
    result = result.capitalize()
    print("I am %d%% confident this is %s" % (prob, result))
Exemple #2
0
def get_image(bot, update):
    global model, lb
    file_id = update.message.photo[-1].file_id
    photo = bot.getFile(file_id)
    photo.download(file_id + '.png')
    img = CropIm(file_id + '.png')
    os.remove(file_id + '.png')
    update.message.reply_text(
        random.choice([
            'Recognition in progress',
            "One moment, I'll check what tree is that", 'Processing...'
        ]))
    label, prob = Classify(img, model, lb)
    print("success")
    result = label.replace("_", " ")
    result = result.capitalize()
    update.message.reply_text("I am %d%% confident this is %s" %
                              (prob, result))
Exemple #3
0
def get_image(bot, update):
    global model, lb
    file_id = update.message.photo[-1].file_id
    #print("hm")
    photo = bot.getFile(file_id)
    #print("got it")
    photo.download(file_id+'.png')
   # print("downloaded")
    img = CropIm(file_id+'.png')
   # print("cropped")
    os.remove(file_id+'.png')
    #print("removed")
    update.message.reply_text(random.choice([
        'Recognition in progress',
        "One moment, I'll check what tree is that",
        'Processing...'
        ]))
    prob, first, second, third = Classify(img)
    print("success")
    if first == "none":
        update.message.reply_text("I'm not sure what is it. Please, try another image1")
    else:
        first = np.array2string(first)
        first = first.replace("_", " ")
        first = first.replace("['", "")
        first = first.replace("']", "")
        first = first.capitalize()
        second = np.array2string(second)
        second = second.replace("_", " ")
        second = second.replace("['", "")
        second = second.replace("']", "")
        second = second.capitalize()
        third = np.array2string(third)
        third = third.replace("_", " ")
        third = third.replace("['", "")
        third = third.replace("']", "")
        third = third.capitalize()
        update.message.reply_text("I am %d%% sure this is %s. It might also be %s or %s, though!" % (prob, first, second, third))
Exemple #4
0
def get_image():
   # global model, lb
    img = CropIm("..\\testim\\acer_platanoides__03.jpg")
    first, second, third = Classify(img)
    print("success")
    if first == "none":
        print("I'm not sure what is it. Please, try another image1")
    else:
        first = np.array2string(first)
        first = first.replace("_", " ")
        first = first.replace("['", "")
        first = first.replace("']", "")
        first = first.capitalize()
        second = np.array2string(second)
        second = second.replace("_", " ")
        second = second.replace("['", "")
        second = second.replace("']", "")
        second = second.capitalize()
        third = np.array2string(third)
        third = third.replace("_", " ")
        third = third.replace("['", "")
        third = third.replace("']", "")
        third = third.capitalize()
        print("This is most probably %s. It might also be %s or %s, though!" % (first, second, third))
Exemple #5
0
import os

args = {
    "model1": '..\\model\\3c98a.model',
    "model2": '..\\model\\5c85a.model',
    "model3": '..\\model\\5c33a200e.model',
    "model4": '..\\model\\6c79a200e.model',
    "lb1": '..\\model\\3c98a.pickle',
    "lb2": '..\\model\\5c85a.pickle',
    "lb3": '..\\model\\5c33a200e.pickle',
    "lb4": '..\\model\\6c79a200e.pickle'
}

# load the image
path = '..\\testim\\acer_platanoides__03.jpg'
image = CropIm(path)
output = cv2.imread(path,3)
 
# pre-process the image for classification
image = cv2.resize(image, (120, 120))
image = image.astype("float") / 255.0
image = img_to_array(image)
image = np.expand_dims(image, axis=0)
# load the trained convolutional neural network and the label
# binarizer
print("[info] loading network...")
model = load_model(args["model4"])
lb = pickle.loads(open(args["lb4"], "rb").read())
 
# classify the input image
print("[info] classifying image...")
IMAGE_DIMS = (120, 120, 3)

#initialize data labels
data = []
labels = []

print("[info] loading paths...")
imagePaths = sorted(list(paths.list_images(args["dataset"])))
random.seed(42)
random.shuffle(imagePaths)

print('[info] loading images...')
for imagePath in imagePaths:
    # image = cv2.imread(imagePath, 3)
    image = CropIm(imagePath)
    # print(imagePath)
    image = cv2.resize(image, (IMAGE_DIMS[1], IMAGE_DIMS[0]))
    image = img_to_array(image)
    data.append(image)

    label = imagePath.split(os.path.sep)[-2]
    labels.append(label)
print('[info] images collected')

data = np.array(data, dtype="float") / 255.0
labels = np.array(labels)
print("[info] data matrix: {:.2f}MB".format(data.nbytes / (1024 * 1000.0)))

lb = LabelBinarizer()
labels = lb.fit_transform(labels)