コード例 #1
0
text_output_filename = "TEXT_" + model_prop.weight_filename

#Initialize Variables
batch_size = 1000
image_color_channel = 3
image_size_w = 224
image_size_h = 224
resume_at_epoch = 0

#Initialize Necessary  Object
confusion_mat = ConfusionMatrixObject()
file_writer = FileWriterObject(f_name=OS_UPPER_PATH + "/" +
                               text_output_filename + ".final")

model = MiniAlexnet(base_lr=model_prop.base_lr,
                    momentum=model_prop.momentum,
                    decay_rate=model_prop.decay_rate,
                    nesterov=model_prop.nesterov)
model.load_weights(weights_file)
model.summary()

confusion_mat = ConfusionMatrixObject()

i = 0
while (True):
    x_test, y_test, test_num = read_labels_batch_out(
        labels_path, (224, 224), (224, 224),
        root_images_folder,
        batch_size=batch_size,
        iteration_num=i,
        random_horizontal_flip=False)
    if (test_num == 0):
val_labels_path = OS_UPPER_PATH + "/Resources/NewModels/splits/CNRPark-EXT/val.txt"
train_root_images_folder = OS_UPPER_PATH + "/Resources/CNR_PARK"
val_root_images_folder = OS_UPPER_PATH + "/Resources/CNR_PARK_EXT/PATCHES"
weight_output_filename = "KERAS_Weights_CNR_Parks_tuned_lr1dc1.h5"
checkpoints_folder = OS_UPPER_PATH + "/Checkpoints"
checkpoint_filename = "weights-improvement-{epoch:02d}-{val_acc:.2f}.hdf5"

#Initialize Variables
batch_size = 64
image_color_channel = 3
image_size_w = 224
image_size_h = 224
resume_at_epoch = 0

model = MiniAlexnet(base_lr=0.0001,
                    momentum=0.9,
                    decay_rate=0.0001,
                    nesterov=False)
model.summary()

x_train, y_train, train_num = read_labels(train_labels_path, (256, 256),
                                          (224, 224),
                                          train_root_images_folder,
                                          batch_size=batch_size,
                                          initial_epoch=resume_at_epoch,
                                          random_horizontal_flip=True)
x_val, y_val, val_num = read_labels(val_labels_path, (224, 224), (224, 224),
                                    val_root_images_folder,
                                    batch_size=batch_size,
                                    initial_epoch=resume_at_epoch,
                                    random_horizontal_flip=True)
#Initialize the camera
cameras = []
cam0 = cv2.VideoCapture(0)  # 0 -> index of camera
cam0_name = "cam0"
cam0_width = 320
cam0_height = 240
cam0.set(3, cam0_width)
cam0.set(4, cam0_height)
cameras.append(cameras)

# Allow the camera to warm up
time.sleep(0.1)

#Model initialize
model = MiniAlexnet(base_lr=0.0001,
                    momentum=0.9,
                    decay_rate=0.0005,
                    nesterov=False)
model.load_weights(weights_file)
model.summary()

#Make sure the cam0 have been activation
if not (cam0.isOpened()):
    cam0.open()

#Get Image From Camera
return_boolean, captured_img = cam0.read()

if (return_boolean):
    cv2.imwrite(OS_UPPER_PATH + "/" + temp_img_name, captured_img)
    garbage_list.append(OS_UPPER_PATH + "/" + temp_img_name)
else: