Beispiel #1
0
def main():
    #print("hello world") for luck
    
    in_arg = train_input_args()
    
    print("   data directory =",in_arg.data_dir, "\n   save directory =", in_arg.save_dir, "\n   model architecture =", in_arg.arch,
          "\n   hidden units =", in_arg.hidden_units, "\n   learning rate =", in_arg.learning_rate,
          "\n   epochs =", in_arg.epochs, "\n   device =", in_arg.device)
    
    image_data, data_loader = load_images()
    
    model, optimizer, criterion = build_model(in_arg.arch , in_arg.hidden_units, in_arg.learning_rate)
    
    model = train_model(model,data_loader, in_arg.epochs, criterion, optimizer, in_arg.device)
    
    save_model(model, optimizer, in_arg.arch, in_arg.data_dir, in_arg.save_dir,image_data)
    
    print("-"*40)      
Beispiel #2
0
import numpy as np
import functions as func

# Download images
X = func.load_images("train-images-idx3-ubyte.gz")

# Input number
try:
    val = int(input('Enter a number 0 or more to 9999 or less: '))
    image = X[val]
    if(val > 9999):
        raise IndexError
except IndexError:
    # IndexError
    print('Invalid index.')
    raise
except:
    # Error
    print('Invalid string.')
    raise

# Run task
y = func.forward(image)
num = np.argmax(y)
print(num)
Beispiel #3
0
#Volleyball simulation
import pygame as pg, math
import functions as fn

pg.init()

#screen size
screen_size=(800,600)

#loads and transforms images
bg,rod,playerr,playerb,volleyball,overlay1,overlay2=fn.load_images()

#loads fonts
TNR1=pg.font.SysFont("Times New Roman", 50)
TNR2=pg.font.SysFont("Times New Roman", 30)

PETC=TNR1.render('Press enter to exit...',1,(0,0,0))
paused=TNR1.render('PAUSED',1,(0,0,0))
welcome=TNR1.render('WELCOME!',1,(0,0,0))
choice=TNR2.render('Select the difficult level:',1,(0,0,0))
choice1=TNR2.render('Easy - Press 1',1,(0,0,0))
choice2=TNR2.render('Medium - Press 2',1,(0,0,0))
choice3=TNR2.render('Difficult - Press 3',1,(0,0,0))

#initializes object for framerate
clock=pg.time.Clock()

#making screen
screen=pg.display.set_mode(screen_size)
pg.display.set_caption('Volleyball')
import numpy as np
import cv2
from matplotlib import pyplot as plt
from functions import load_images
from functions import filter_image
from functions import analyze_derivative
from functions import get_half_width_on_half_hight

# Load images
original_images, images_names = load_images("*.bmp")
assert len(original_images) > 0
print("found " + str(len(original_images)) + " images")

for i, image, image_name in zip(range(len(original_images)), original_images,
                                images_names):
    print('processing', i, 'image')

    fil_im = filter_image(image,
                          vetrical_alignment=30,
                          horizontal_alignment=30)
    img_der = analyze_derivative(fil_im,
                                 axis=1,
                                 name=image_name[:-4] + "_derivative")

    temp_slice = img_der[1000, :].copy()

    widths = np.zeros(4)

    env_size = 50
    for i in range(4):
        ind_max, widths[i] = get_half_width_on_half_hight(temp_slice, env_size)
from keras.models import load_model

from functions import SAVED_MODEL_PATH, TRAINING_PATH, EVALUATE_PATH, get_latest_model, load_images

########################################################################################################################

model_name = get_latest_model()
model = load_model(model_name)
print('-' * 80)
print("Loaded model " + model_name)
# model.summary()

########################################################################################################################

print("Loading evaluation dataset ...")
X_test, y_test = load_images(EVALUATE_PATH, 68, 69)
print("... done!")
print(X_test.shape, y_test.shape)

y_predict = model.predict(X_test)[0]
y_predict = cv2.normalize(y_predict,
                          None,
                          alpha=0,
                          beta=255,
                          norm_type=cv2.NORM_MINMAX,
                          dtype=cv2.CV_8U)

mask = cv2.normalize(y_test[0],
                     None,
                     alpha=0,
                     beta=255,
Beispiel #6
0
from keras.models import load_model

from functions import SAVED_MODEL_PATH, TRAINING_PATH, EVALUATE_PATH, get_latest_model, load_images

########################################################################################################################

# Training parameters
batch_size = 16
epochs = 6

TIME = 3

########################################################################################################################

print("Loading training dataset ...")
X_train, y_train = load_images(TRAINING_PATH, 0, 10000)
# X_train, y_train = load_images(TRAINING_PATH, 5000 * TIME, 5000 * (TIME + 1))
print("... done!")
print(X_train.shape, y_train.shape)

print("Loading evaluation dataset ...")
X_test, y_test = load_images(EVALUATE_PATH, 0, 500)
print("... done!")
print(X_test.shape, y_test.shape)

########################################################################################################################

model_name = get_latest_model()
model = load_model(model_name)
print('-' * 80)
print("Loaded model " + model_name)
from keras.applications import vgg16, inception_v3, resnet50, mobilenet

tensorflow_master = ""
checkpoint_path = "NIPS/inception-v3/inception_v3.ckpt"
input_dir = "NIPS/images"
max_epsilon = 16.0
image_width = 299
image_height = 299
batch_size = 1000
eps = 2.0 * max_epsilon / 255.0
batch_shape = [batch_size, image_height, image_width, 3]
num_classes = 1001

categories = pd.read_csv("NIPS/categories.csv")
image_classes = pd.read_csv("NIPS/images.csv")
image_iterator = load_images(input_dir, batch_shape)

# get first batch of images
filenames, images = next(image_iterator)

image_metadata = pd.DataFrame({
    "ImageId": [f[:-4] for f in filenames]
}).merge(image_classes, on="ImageId")
true_classes = image_metadata["TrueLabel"].tolist()
target_classes = true_labels = image_metadata["TargetClass"].tolist()

#true_classes_names = (pd.DataFrame({"CategoryId": true_classes})
#                        .merge(categories, on="CategoryId")["CategoryName"].tolist())

true_classes_names = []
for i in true_classes: