예제 #1
0
def flyaction(listbox, listbox2, airportstuple):
    # first check if anything on the list has been chosen
    if (airportindices[0] > 0) and (airportindices[1] > 0):
        # check if start differs from destination
        if airportindices[0] != airportindices[1]:
            print "Starting flight simulation..."
            start = (float(airportstuple[airportindices[0]][3]),
                     float(airportstuple[airportindices[0]][4]),
                     float(airportstuple[airportindices[0]][5]))
            destination = (float(airportstuple[airportindices[1]][3]),
                           float(airportstuple[airportindices[1]][4]),
                           float(airportstuple[airportindices[1]][5]))
            airplane = Boeing747(
            )  # type of the plane should be possible to choose in the future
            airplane.fly(start, destination)
            data = airplane.flightdata()
            print "...done!"
            viewer = DataViewer(data)
            viewer.start()
        else:
            print "Start and destination are identical!"
            return
    else:
        print "Must choose start and destination!"
        return
예제 #2
0
class MainWindow(Frame):
    def __init__(self):
        super().__init__()
        self.master.title("Main Menu")
        self.__installButton = Button(self.master, text="Set API key",\
          command=self.installApiKey)
        self.__enterDataButton = Button(self.master, text="View Data",\
          command=self.viewData)
        self.__viewResults = Button(self.master, text="View Results",\
          command=self.viewResults)

        self.__displayFrame = None
        self.__installButton.pack(fill=X)
        self.__enterDataButton.pack(fill=X)
        self.__viewResults.pack(fill=X)

    def installApiKey(self):
        ApiConfig().show()

    def viewData(self):
        if self.__displayFrame is not None:
            self.__displayFrame.destroy()
        self.__displayFrame = DataViewer()
        self.__displayFrame.pack(fill=X)

    def viewResults(self):
        ResultsViewer().show()
예제 #3
0
def main():
    ImagePath = "./busesAug"
    AnnotationFile = "./annotationsTestAug.txt"
    OutImgPath = "./BusesOnly"
    pDV = DataViewer.CDataViewer()
    pDA = DataAugmentation.CDataAugmentation()
    OsUtils.remove(OutImgPath)
    os.mkdir(OutImgPath)
    for label in range(1, 7):
        os.mkdir(OutImgPath + "\\" + str(label))
    ImageList = pDV.LoadImages(ImagePath)
    DetectedObjects = pDV.LoadAnnotations(AnnotationFile)
    print("extracting data")
    for ImageFullPathFile in ImageList:
        FileName = os.path.basename(ImageFullPathFile)
        BoxList = DetectedObjects[FileName]
        if BoxList:
            #pDV.PlotBoxes(ImageFullPathFile,BoxList)
            pDV.SaveBoxesAsImages(ImageFullPathFile, BoxList, OutImgPath)
        pass
    pass
    print("finished extracting data")
    print("begining data augmentation")
    #pDA.rotate(OutImgPath, OutImgPath)
    #pDA.flip(OutImgPath,OutImgPath)
    print("finished data augmentation")
예제 #4
0
 def draw(self):
     labelFontFamily = self.getLabelFontFamily()
     labelFontSize = self.getLabelFontSize()
     cellFontSize = self.getCellFontSize()
     cellFontFamily = self.getCellFontFamily()
     top = Tk.Toplevel()
     DV.DataTable(top,
                  self.a,
                  name=self.getPLATFORM(),
                  labelFamily=labelFontFamily,
                  labelSize=labelFontSize,
                  cellFamily=cellFontFamily,
                  cellSize=cellFontSize)
예제 #5
0
def flyaction(listbox, listbox2, airportstuple):
    # first check if anything on the list has been chosen
    if (airportindices[0] > 0) and (airportindices[1] > 0):
        # check if start differs from destination
        if airportindices[0] != airportindices[1]:
            print "Starting flight simulation..."
            start = (float(airportstuple[airportindices[0]][3]), float(airportstuple[airportindices[0]][4]),
                     float(airportstuple[airportindices[0]][5]))
            destination = (float(airportstuple[airportindices[1]][3]), float(airportstuple[airportindices[1]][4]),
                     float(airportstuple[airportindices[1]][5]))
            airplane = Boeing747()  # type of the plane should be possible to choose in the future
            airplane.fly(start, destination)
            data = airplane.flightdata()
            print "...done!"
            viewer = DataViewer(data)
            viewer.start()
        else:
            print "Start and destination are identical!"
            return
    else:
        print "Must choose start and destination!"
        return
예제 #6
0
 def viewData(self):
     if self.__displayFrame is not None:
         self.__displayFrame.destroy()
     self.__displayFrame = DataViewer()
     self.__displayFrame.pack(fill=X)
예제 #7
0
def main():

    ImagePath = "./busesTrain"
    AnnotationFile = "./annotationsTrain.txt"
    AnnotationOutputFile = "./annotationsTrainAug.txt"
    OutImgPath = "./BusesAug"

    AnnotationOutputFile = "./annotationsTestAug.txt"
    OutImgPath = "./BusesAug"
    TestMode = True

    pDV = DataViewer.CDataViewer()

    OsUtils.remove(OutImgPath)
    os.mkdir(OutImgPath)
    ImageList = pDV.LoadImages(ImagePath)
    LabelsDict = pDV.LoadAnnotations(AnnotationFile)
    x1Offset = -20
    y1Offset = -20
    x2Offset = 20
    y2Offset = 20

    x1Offset = 0
    y1Offset = 0
    x2Offset = 0
    y2Offset = 0

    LabelsDictAug = GetBoundingBoxAndLabel(LabelsDict, x1Offset, y1Offset,
                                           x2Offset, y2Offset)

    #ia.seed(1)
    NumberOfAugRuns = 2
    seq = iaa.Sequential(
        [
            #iaa.Affine(rotate=(-90, 90)),
            #iaa.AdditiveGaussianNoise(scale=(10, 60)),
            #iaa.GaussianBlur(sigma=(0, 0.5)),
            #iaa.ContrastNormalization((0.75, 1.5)),
            #iaa.Multiply((0.8, 1.2), per_channel=0.2),
            #iaa.Crop(percent=(0, 0.2))
            #iaa.fliplr(0.5),
            iaa.Multiply((0.8, 1.2)),
            iaa.Affine(
                #scale=(0.5, 1.5),
                #translate_percent={"x": (-0.2, 0.2), "y": (-0.2, 0.2)},
                rotate=(-180, 180), )
        ],
        random_order=True)
    AugRes = {}
    for i in range(1, NumberOfAugRuns + 1):
        print("iteration  {:d}".format(i))
        for img_path in ImageList:
            fileName = os.path.basename(img_path)
            Boxes, Labels = LabelsDictAug[fileName]
            img = imageio.imread(img_path)
            bbs = BoundingBoxesOnImage(Boxes, shape=img.shape)
            fileNameAug = "Aug" + str(i) + "_" + fileName

            images_aug, bbs_aug = seq(image=img, bounding_boxes=bbs)

            #image_before = bbs.draw_on_image(img, size=4)
            #image_after = bbs_aug.draw_on_image(images_aug, size=4, color=[0, 0, 255])
            #ia.imshow(image_before)
            #ia.imshow(image_after)

            np_image = np.hstack([images_aug])
            #ia.imshow(np_image)
            im = Image.fromarray(np_image)
            saveStr = OutImgPath + "\\" + fileNameAug
            im.save(saveStr)
            AugRes[fileNameAug] = BoxTolist(bbs_aug)

    WriteResults(AugRes, AnnotationOutputFile, TestMode)
예제 #8
0
def main():


    ImagePath = "./busesTrain"
    AnnotationFile = "./annotationsTrainOneClass.txt"
    ImagePath = "./BusesAug"
    AnnotationFile = "./annotationsTrainAug.txt"
    pDV = DataViewer.CDataViewer()
    ImageList = pDV.LoadImages(ImagePath)
    Labels = pDV.LoadAnnotations(AnnotationFile)

    # train on the GPU or on the CPU, if a GPU is not available
    device = torch.device('cuda') if torch.cuda.is_available() else torch.device('cpu')
    print(torch.cuda.get_device_capability(0))
    #device = torch.device('cpu')


    # our dataset has two classes only - background and person
    #6 buses and one for all others
    #num_classes = 6 + 1
    num_classes = 2
    num_epochs = 4
    # use our dataset and defined transformations
    dataset = BussesDataset(ImageList,Labels, get_transform(train=True))
    dataset_test = BussesDataset(ImageList,Labels, get_transform(train=False))

    # split the dataset in train and test set
    indices = torch.randperm(len(dataset)).tolist()
    NumberOfItem = len(indices)
    NumberOfItemForTrain = int(0.9*NumberOfItem)
    NumberOfItemForTest = NumberOfItem - NumberOfItemForTrain
    dataset = torch.utils.data.Subset(dataset, indices[:NumberOfItemForTrain])
    dataset_test = torch.utils.data.Subset(dataset_test, indices[NumberOfItemForTrain:])

    # define training and validation data loaders
    #TO-DO : need to implement my own data loader

    data_loader = torch.utils.data.DataLoader(
        dataset, batch_size=1, shuffle=True,
        collate_fn=utils.collate_fn,pin_memory=True)

    data_loader_test = torch.utils.data.DataLoader(
        dataset_test, batch_size=1, shuffle=False,
        collate_fn=utils.collate_fn,pin_memory=True)

    # get the model using our helper function
    model = get_model_instance(num_classes)
    print(model)
    # move model to the right device
    model.to(device)

    # construct an optimizer
    params = [p for p in model.parameters() if p.requires_grad]
    optimizer = torch.optim.SGD(params, lr=0.005,
                                momentum=0.9, weight_decay=0.0005)
    # and a learning rate scheduler
    lr_scheduler = torch.optim.lr_scheduler.StepLR(optimizer,step_size=3,gamma=0.1)

    # let's train it for 10 epochs


    for epoch in range(num_epochs):
        # train for one epoch, printing every 10 iterations
        train_one_epoch(model, optimizer, data_loader, device, epoch, print_freq=10)
        # update the learning rate
        lr_scheduler.step()
        # evaluate on the test dataset
        evaluate(model, data_loader_test, device=device)
        saveStr = "busModelV9" + str(epoch) + ".ptn"
        torch.save(model.state_dict(), saveStr)
    torch.save(model.state_dict(), "busModelV9.pth")
    print("That's it!")
예제 #9
0
import imgaug as ia
import imgaug.augmenters as iaa
from imgaug.augmentables.bbs import BoundingBox, BoundingBoxesOnImage
import DataViewer

pDV = DataViewer.CDataViewer()
AnnotationFile = "./annotationsTrain.txt"
LabelsDict = pDV.LoadAnnotations(AnnotationFile)
boxes = []
labels = []
LabelsDictAug = {}
for key, boxlist in LabelsDict.items():
    for value in boxlist:
        # Create a Rectangle patch
        x = value[0]
        y = value[1]
        w = value[2]
        l = value[3]
        label = value[4]
        x1 = x
        y1 = y
        x2 = x1 + w
        y2 = y1 + l
        CurrentBox = BoundingBox(x1=x1, y1=y1, x2=x2, y2=y2)
        boxes.append(CurrentBox)
        labels.append(label)
    LabelsDictAug[key] = [boxes,labels]



ia.seed(1)