Esempio n. 1
0
#root_path = "/home/michal/dataset/background/"

dataset = Dataset(96, 96, 10000, 1000, root_path)

 

testing_loss_sum_best = None

nets_to_try = 1

for net in range(nets_to_try):

    epoch_count     = 20
    learning_rates  = [0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.0001, 0.00001, 0.00001]

    model = Model(dataset.training.input_shape, dataset.training.output_shape[0])

    for epoch in range(epoch_count):
        
        batch_size  = 32 
        batch_count = (dataset.training.get_count()+batch_size) // batch_size

        learning_rate = learning_rates[epoch%len(learning_rates)]
        
        optimizer  = torch.optim.Adam(model.parameters(), lr= learning_rate, weight_decay=10**-6)  

        training_loss_sum = 0.0
        for batch_id in range(batch_count):
            training_x, training_y = dataset.training.get_batch(batch_size)

            training_x = training_x.to(model.device)
import numpy
import cv2
import torch
import time
from models.net_1.model import Model

model_input_width = 512  #96
model_input_height = 512  #96

model = Model((1, model_input_height, model_input_width), 2)
model.load("models/net_1/")

cap = cv2.VideoCapture("/Users/michal/Movies/line_path_video.mp4")
input_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
input_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
'''
#cap = cv2.VideoCapture(0)
input_width        = 640
input_height       = 480
cap.set(cv2.CAP_PROP_FRAME_WIDTH,input_width)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT,input_height)
'''


def get_prediction(frame):
    frame_grayscale = numpy.array(cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY))
    frame_resized = cv2.resize(frame_grayscale,
                               (model_input_width, model_input_height),
                               interpolation=cv2.INTER_AREA)

    frame_normalised = numpy.clip(frame_resized / 255.0, 0, 1)
Esempio n. 3
0
        macs = 4 * size

        print("export_ReLU :")
        print("IO shape        ", output_shape)
        print("macs            ", macs)
        print("\n\n")

        return code, output_shape, size, macs

    def quantize(self, weights, bias):
        tmp = numpy.concatenate([weights.flatten(), bias.flatten()])
        scale = numpy.std(tmp) * 2

        result_weights = numpy.clip((weights * 128) / scale, -127,
                                    127).astype(numpy.int8)
        result_bias = numpy.clip((bias * 128) / scale, -127,
                                 127).astype(numpy.int8)

        return result_weights, result_bias, scale


model_input_height = 192
model_input_width = 192
model_output_channels = 1

model = Model((1, model_input_height, model_input_width),
              model_output_channels)
model.load("models/net_1/")

export = ExportNetwork(model, model_input_height, model_input_width, 1)