示例#1
0
def draw_row(canvas:Canvas, row:tuple, top_left:tuple, pixel:int=25):
    x = top_left[0]
    y = top_left[1]
    # you could also make a palette and each cell number 
    # could access a color in the palette:
    palette = [None, '#E0607E', 'black', 'white']
    for cell in row:
        if cell != 0:
            fill = palette[cell]
            make_square(canvas, (x, y), pixel, fill_color=fill)
        x += pixel
示例#2
0
def run_inference(inf_file):
    # Preprocessing of the image happens here
    img = load_image(inf_file)
    print("Image Loaded")
    img = make_square(img)
    img = augment(prep, img)
    print("Transformations done")
    img = img.transpose(-1, 0, 1).astype(np.float32)
    img = img.reshape(-1, CHANNELS, IMG_WIDTH, IMG_HEIGHT)

    # Inferencing starts here
    sess = onnxruntime.InferenceSession("./best_acc.onnx")
    print("The model expects input shape: ", sess.get_inputs()[0].shape)
    print("The shape of the Image is: ", img.shape)
    input_name = sess.get_inputs()[0].name

    result = sess.run(None, {input_name: img})
    prob_array = result[0][0]
    print("Prob Array ", prob_array)
    prob = max(softmax(result[0][0]))
    print("Prob ", prob)
    species = tf.argmax(prob_array.ravel()[:10]).numpy()
    print("Class Label ", species)
    print("Spec ", CLASS_MAP[species][1])
    string_label = CLASS_MAP[species][1].split(" ")
    return (string_label[0], string_label[1], str(prob), color_code(prob))
示例#3
0
def draw_row(canvas:Canvas, row:tuple, top_left:tuple, pixel:int=25):
    x = top_left[0]
    y = top_left[1]
    for cell in row:
        if cell == 1:
            make_square(canvas, (x, y), pixel, fill_color='#E0607E')
        elif cell == 2:
            make_square(canvas, (x, y), pixel, fill_color='black')
        elif cell == 3:
            make_square(canvas, (x, y), pixel, fill_color='white')
        x += pixel
示例#4
0
def run_inference(inf_file):
    # Preprocessing of the image happens here
    img = load_image(inf_file)
    originalimg = img
    #Cropping line is below, SHOULD NOT BE INCLUDED IN THIS VERSION
    #useless, img, status=cropImage(impath, 'm', labelsfile, 21, 0.08)
    print("Image Loaded")
    img = make_square(img)
    img = augment(prep, img)
    print("Transformations done")
    img = img.transpose(-1, 0, 1).astype(np.float32)
    img = img.reshape(-1, CHANNELS, IMG_WIDTH, IMG_HEIGHT)

    # Inferencing starts here
    sess = onnxruntime.InferenceSession("./best_acc.onnx")
    print("The model expects input shape: ", sess.get_inputs()[0].shape)
    print("The shape of the Image is: ", img.shape)
    input_name = sess.get_inputs()[0].name

    result = sess.run(None, {input_name: img})
    prob_array = result[0][0]
    print("Prob Array ", prob_array)
    prob = max(softmax(result[0][0]))
    print("Prob ", prob)
    species = tf.argmax(prob_array.ravel()[:20]).numpy()
    print("Class Label ", species)
    print("Spec ", CLASS_MAP[species][1])
    string_label = CLASS_MAP[species][1].split(" ")

    #fullfilename = mosquitoid + "_" + picnum + "_" + string_label[0] + "_" + string_label[1]
    #fullbucket = 'photostakenduringpilotstudy'
    #s3_file = 'PilotStudy'
    #file = cv2.imwrite(fullfilename, originalimg)
    #upload_to_aws(file, fullbucket , s3_file)
    ##upload_file(file, fullbucket)

    return (string_label[0], string_label[1], str(prob), color_code(prob))
示例#5
0
# value of your y coordinate as shown below.
#
# Now, how could you convert the program below to a function so that you
# could create multiple frankensteins drawn at different sizes, colors, and
# position?

# frankenstein anchored at position (x, y)
pixel = 20
top_left = (100, 50)
body_color = '#5ec031'
pants_color = 'hotpink'
x = top_left[0]
y = top_left[1]

# row 1
make_square(canvas, (x + 2 * pixel, y), pixel, fill_color='black')
make_square(canvas, (x + 3 * pixel, y), pixel, fill_color='black')
make_square(canvas, (x + 4 * pixel, y), pixel, fill_color='black')
make_square(canvas, (x + 5 * pixel, y), pixel, fill_color='black')
make_square(canvas, (x + 6 * pixel, y), pixel, fill_color='black')

# row 2
make_square(canvas, (x + 2 * pixel, y + pixel), pixel, fill_color=body_color)
make_square(canvas, (x + 3 * pixel, y + pixel), pixel, fill_color=body_color)
make_square(canvas, (x + 4 * pixel, y + pixel), pixel, fill_color=body_color)
make_square(canvas, (x + 5 * pixel, y + pixel), pixel, fill_color=body_color)
make_square(canvas, (x + 6 * pixel, y + pixel), pixel, fill_color=body_color)

# row 3
make_square(canvas, (x + 2 * pixel, y + 2 * pixel),
            pixel,
示例#6
0
from itertools import product

import matplotlib.pyplot as plt
from neupy import algorithms, utils, init

from helpers import plot_2d_grid, make_circle, make_elipse, make_square

plt.style.use('ggplot')
utils.reproducible()

if __name__ == '__main__':
    GRID_WIDTH = 4
    GRID_HEIGHT = 4

    datasets = [
        make_square(),
        make_circle(),
        make_elipse(corr=0.7),
    ]
    configurations = [{
        'weight_init': init.Uniform(0, 1),
        'title': 'Random uniform initialization',
    }, {
        'weight_init': 'sample_from_data',
        'title': 'Sampled from the data',
    }, {
        'weight_init': 'init_pca',
        'title': 'Initialize with PCA',
    }]

    plt.figure(figsize=(15, 15))
示例#7
0
# Note that each of the x-positions can be re-written in terms of
# the pixel value. The advantage of rewriting your code in this
# way is that it allows you to be able to scale your frankenstein.
# In other words, if you update the size of the pixel (using the
# pixel variable below), the monster scales.

# However, no matter what, frankenstein is still anchored at
# position (0, 0). How could you alter this program so that frank
# could be drawn *anywhere on the screen?

pixel = 25
body_color = '#5ec031'
pants_color = 'hotpink'

# row 1                                                                        # before:
make_square(canvas, (2 * pixel, 0), pixel, fill_color='black')  # (50, 0), 25
make_square(canvas, (3 * pixel, 0), pixel, fill_color='black')  # (75, 0), 25
make_square(canvas, (4 * pixel, 0), pixel, fill_color='black')  # (100, 0), 25
make_square(canvas, (5 * pixel, 0), pixel, fill_color='black')  # (125, 0), 25
make_square(canvas, (6 * pixel, 0), pixel, fill_color='black')  # (150, 0), 25

# row 2
make_square(canvas, (2 * pixel, pixel), pixel,
            fill_color=body_color)  # (50, 25), 25
make_square(canvas, (3 * pixel, pixel), pixel,
            fill_color=body_color)  # (75, 25), 25
make_square(canvas, (4 * pixel, pixel), pixel,
            fill_color=body_color)  # (100, 25), 25
make_square(canvas, (5 * pixel, pixel), pixel,
            fill_color=body_color)  # (125, 25), 25
make_square(canvas, (6 * pixel, pixel), pixel,
示例#8
0
def draw_row(canvas: Canvas, row: tuple, top_left: tuple, pixel: int = 25):
    x = top_left[0]
    y = top_left[1]
    for cell in row:
        make_square(canvas, (x, y), pixel, fill_color='grey')
        x += pixel
示例#9
0
from helpers import make_square, make_grid

# initialize window
gui = Tk()
canvas = Canvas(gui, width=600, height=600, background='white')
canvas.pack()

########################## YOUR CODE BELOW THIS LINE ##############################

# helper function that draws a grid.
make_grid(canvas, 600, 600)

body_color = '#5ec031'

# row 1
make_square(canvas, (50, 0), 25, fill_color='black')                 # pixel (3, 1)
make_square(canvas, (75, 0), 25, fill_color='black')                 # pixel (4, 1)
make_square(canvas, (100, 0), 25, fill_color='black')                # pixel (5, 1)
make_square(canvas, (125, 0), 25, fill_color='black')                # pixel (6, 1)
make_square(canvas, (150, 0), 25, fill_color='black')                # pixel (7, 1)

# row 2
make_square(canvas, (50, 25), 25, fill_color=body_color)             # pixel (3, 2)
make_square(canvas, (75, 25), 25, fill_color=body_color)             # pixel (4, 2)
make_square(canvas, (100, 25), 25, fill_color=body_color)            # pixel (5, 2)
make_square(canvas, (125, 25), 25, fill_color=body_color)            # pixel (6, 2)
make_square(canvas, (150, 25), 25, fill_color=body_color)            # pixel (7, 2)

# row 3
make_square(canvas, (50, 50), 25, fill_color=body_color)             # pixel (3, 3)
make_square(canvas, (75, 50), 25, fill_color=body_color)             # pixel (4, 3)