Esempio n. 1
0
# Option: skip the training of the neural network (debugging)
SKIP_TRAINING = True

# Code starts
if not LOAD_FROM_CACHE:
    # Load training / testing data
    print("Loading training and testing data...")
    training, testing = [], []  # Array of tuples: (image, answer)
    category_count = len(fUtil.TRAINING_DATA_NAMES)
    for category in fUtil.TRAINING_DATA_NAMES:
        # Print the progress
        print(">> Loading " + fUtil.get_name(fUtil.get_index(category)) +
              "... (" + str(fUtil.get_index(category) + 1) + "/" +
              str(category_count) + ")")
        # Normalize the data for more efficiency
        data = fUtil.load_data(category, normalize=True)
        # Split the data into training data and testing data
        train_limit = int(len(data) * TRAIN_TEST_RATIO)
        index = fUtil.get_index(category)
        # Append the current data to master data list
        training += [(image_data,
                      [1 if a == index else 0 for a in range(category_count)])
                     for image_data in data[:train_limit]]
        testing += [(image_data,
                     [1 if a == index else 0 for a in range(category_count)])
                    for image_data in data[train_limit:]]

    # Shuffle training / testing data
    print("Shuffling training and testing data...")
    random.shuffle(training)
    random.shuffle(testing)
Esempio n. 2
0
    def clear(event):
        nonlocal draw_data
        event.widget.delete("all")
        draw_data = [[0] * 28 for _ in range(28)]
        
    def done(_):
        master.destroy()
    
    master = tk.Tk()
    canvas = tk.Canvas(master, width=560, height=560)
    canvas.pack()
    canvas.bind('<ButtonPress-1>', draw)
    canvas.bind('<B1-Motion>', draw)
    canvas.bind('<Double-1>', clear)
    canvas.bind('<ButtonPress-2>', done)
    
    master.mainloop()
    return np.array([a for b in draw_data for a in b])

    
if __name__ == "__main__":
    dataset_index = -3
    data = fUtil.load_data(fUtil.TRAINING_DATA_NAMES[dataset_index])
    name = fUtil.TRAINING_DATA_NAMES[dataset_index][:1].upper() + fUtil.TRAINING_DATA_NAMES[dataset_index][1:-4]
    show_image(data[0])
    show_image(data, bulk_size=49, name=name)
    data = show_drawable_canvas()
    print(data)
    show_image(data)