Beispiel #1
0
 def print_loss(self):
     info = 'Loss: ' + \
            'B-sem_acc: {:.4f} | B-sem_miou: {:.4f} | B-ce_loss: {:.4f} | '.format(
                to_number(self.loss_sem_acc),
                to_number(self.loss_sem_miou),
                to_number(self.loss_semantic))
     return info
Beispiel #2
0
    def __init__(self, config, machine, starttime, **kwargs):

        BatchJob.__init__(self, config, machine, starttime, **kwargs)

        # Set of configuration Namespace objects.
        grid = self.config_namespace(kwargs.get('grid'))
        self.grid = grid

        self.nml = {}
        for sect, keys in kwargs.get('nml', {}).items():
            self.nml[sect] = {}
            for key, value in keys.items():
                if isinstance(value, str):
                    try:
                        tmp = value.format(grid=self.grid, n=self.config)

                    except AttributeError:
                        tmp = eval("f'{}'".format(value))

                    self.nml[sect][key] = utils.to_number(tmp)

                elif isinstance(value, list):
                    tmp = [
                        v.format(grid=self.grid, n=self.config) for v in value
                    ]
                    self.nml[sect][key] = [utils.to_number(v) for v in tmp]
                else:
                    self.nml[sect][key] = value
Beispiel #3
0
 def _parse_bounds(self, node):
     if node.attributes.has_key('minlat'):
         self.gpx.min_latitude = mod_utils.to_number(node.attributes['minlat'].nodeValue)
     if node.attributes.has_key('maxlat'):
         self.gpx.min_latitude = mod_utils.to_number(node.attributes['maxlat'].nodeValue)
     if node.attributes.has_key('minlon'):
         self.gpx.min_longitude = mod_utils.to_number(node.attributes['minlon'].nodeValue)
     if node.attributes.has_key('maxlon'):
         self.gpx.min_longitude = mod_utils.to_number(node.attributes['maxlon'].nodeValue)
Beispiel #4
0
 def _parse_bounds(self, node):
     if node.attrib.get('minlat'):
         self.gpx.min_latitude = mod_utils.to_number(node.attrib.get('minlat'))
     if node.attrib.get('maxlat'):
         self.gpx.min_latitude = mod_utils.to_number(node.attrib.get('maxlat'))
     if node.attrib.get('minlon'):
         self.gpx.min_longitude = mod_utils.to_number(node.attrib.get('minlon'))
     if node.attrib.get('maxlon'):
         self.gpx.min_longitude = mod_utils.to_number(node.attrib.get('maxlon'))
Beispiel #5
0
 def _parse_bounds(self, node):
     if node.attributes.has_key("minlat"):
         self.gpx.min_latitude = mod_utils.to_number(node.attributes["minlat"].nodeValue)
     if node.attributes.has_key("maxlat"):
         self.gpx.min_latitude = mod_utils.to_number(node.attributes["maxlat"].nodeValue)
     if node.attributes.has_key("minlon"):
         self.gpx.min_longitude = mod_utils.to_number(node.attributes["minlon"].nodeValue)
     if node.attributes.has_key("maxlon"):
         self.gpx.min_longitude = mod_utils.to_number(node.attributes["maxlon"].nodeValue)
Beispiel #6
0
def generate_data(instance):
    data_header = []

    for folder in instance.folders:

        folder_item = None
        folder_date_added = preset.no_date
        folder_date_modified = preset.no_date
        folder_guid = preset.empty
        folder_id = preset.empty
        folder_last_visited = preset.no_date
        folder_name = preset.empty
        folder_sync_transaction_version = preset.empty
        folder_type = preset.empty
        folder_url = preset.empty

        for item in folder:
            if item == preset.children:
                folder_item = read_content(folder[item])
            elif item == preset.meta_info:
                for element in folder[item]:
                    if element == preset.last_visited:
                        folder_last_visited = folder[item][element]
            elif item == preset.date_added:
                folder_date_added = folder[item]
            elif item == preset.date_modified:
                folder_date_modified = folder[item]
            elif item == preset.guid:
                folder_guid = folder[item]
            elif item == preset.item_id:
                folder_id = folder[item]
            elif item == preset.item_name:
                folder_name = folder[item]
            elif item == preset.sync_transaction_version:
                folder_sync_transaction_version = folder[item]
            elif item == preset.item_type:
                folder_type = folder[item]
            elif item == preset.url:
                folder_url = folder[item]
            else:
                tools.debug(preset.message["warning"] + str(item))

        folder_data = (folder_guid, utils.to_number(folder_id),
                       utils.to_number(folder_sync_transaction_version),
                       folder_type, utils.to_date(folder_date_added),
                       utils.to_date(folder_date_modified),
                       utils.to_date(folder_last_visited), folder_name,
                       folder_url)
        for item in folder_item:
            data_header.append(folder_data + item + preset.trail)
    return data_header
Beispiel #7
0
def read_content(folder_items):
    url_list = []
    for folder_item in folder_items:
        url_date_added = preset.empty
        url_date_modified = preset.empty
        url_guid = preset.empty
        url_item_id = preset.empty
        url_last_visited = preset.empty
        url_name = preset.empty
        url_sync_transaction_version = preset.empty
        url_item_type = preset.empty
        url_address = preset.empty
        url_icon = preset.empty
        for item in folder_item:
            if item == preset.children:
                read_content(folder_item[item])
            elif item == preset.meta_info:
                for element in folder_item[item]:
                    if element == preset.last_visited:
                        url_last_visited = folder_item[item][element]
            elif item == preset.date_added:
                url_date_added = folder_item[item]
            elif item == preset.date_modified:
                url_date_modified = folder_item[item]
            elif item == preset.guid:
                url_guid = folder_item[item]
            elif item == preset.icon:
                url_icon = folder_item[item]
            elif item == preset.item_id:
                url_item_id = folder_item[item]
            elif item == preset.item_name:
                url_name = folder_item[item]
            elif item == preset.sync_transaction_version:
                url_sync_transaction_version = folder_item[item]
            elif item == preset.item_type:
                url_item_type = folder_item[item]
            elif item == preset.url:
                url_address = folder_item[item]
            else:
                tools.debug(preset.message["warning"] + str(item))
        url_data = (url_guid, utils.to_number(url_item_id),
                    utils.to_number(url_sync_transaction_version),
                    url_item_type, utils.to_date(url_date_added),
                    utils.to_date(url_date_modified),
                    utils.to_date(url_last_visited), url_name,
                    htmlSupport.clean_url(url_address), url_address, url_icon)
        parsed_url = htmlSupport.parse_url(url_address)
        url_list.append(url_data + parsed_url)
    return url_list
Beispiel #8
0
    def step(self, batch, set_):
        self.input.data.copy_(batch[0])
        self.bn(self.input)
        self.bn_de(self.input)

        self.input.data.fill_(0)
        self.bn_de.apply(utils.disableBNRunningMeanStd)
        self.bn_de(self.input)
        self.bn_de.apply(utils.enableBNRunningMeanStd)
        print(self.bn.running_var.size())
        print(self.bn.running_mean.size())
        print("bn mean/var")
        print(self.bn.running_mean)
        print(self.bn.running_var)
        print("bn_de mean/var")
        print(self.bn_de.running_mean)
        print(self.bn_de.running_var)
        self.target.data.copy_(batch[1])
        self.out = self.forward(self.input)
        res = {
            "input_mean": batch[0].mean(),
            "target_mean": batch[1].float().mean(),
            "input_min": batch[0].min(),
            "target_min": batch[1].min(),
            "input_max": batch[0].max(),
            "target_max": batch[1].max(),
        }
        return utils.to_number(res)
Beispiel #9
0
    def _parse_bounds(self, node):
        minlat = self.xml_parser.get_node_attribute(node, 'minlat')
        if minlat:
            self.gpx.min_latitude = mod_utils.to_number(minlat)

        maxlat = self.xml_parser.get_node_attribute(node, 'maxlat')
        if maxlat:
            self.gpx.min_latitude = mod_utils.to_number(maxlat)

        minlon = self.xml_parser.get_node_attribute(node, 'minlon')
        if minlon:
            self.gpx.min_longitude = mod_utils.to_number(minlon)

        maxlon = self.xml_parser.get_node_attribute(node, 'maxlon')
        if maxlon:
            self.gpx.min_longitude = mod_utils.to_number(maxlon)
Beispiel #10
0
def _extract_total(total_el):
    try:
        p_link = total_el.contents[0]
        total_text = p_link.contents[0]
        return to_number(total_text)
    except:
        return 0
Beispiel #11
0
 def evaluate(self, x_i, y_i):
     with torch.no_grad():
         preds = self.model(x_i)
         predicted = torch.argmax(preds.data, 1)
         rlt = predicted == y_i
         accuracy = float(to_number(rlt.sum())) / y_i.shape[0]
     return accuracy
Beispiel #12
0
    def _parse_bounds(self, node):
        minlat = self.xml_parser.get_node_attribute(node, 'minlat')
        if minlat:
            self.gpx.min_latitude = mod_utils.to_number(minlat)

        maxlat = self.xml_parser.get_node_attribute(node, 'maxlat')
        if maxlat:
            self.gpx.min_latitude = mod_utils.to_number(maxlat)

        minlon = self.xml_parser.get_node_attribute(node, 'minlon')
        if minlon:
            self.gpx.min_longitude = mod_utils.to_number(minlon)

        maxlon = self.xml_parser.get_node_attribute(node, 'maxlon')
        if maxlon:
            self.gpx.min_longitude = mod_utils.to_number(maxlon)
Beispiel #13
0
    def step(self, batch, set_):
        if random.random() < self.p_red:
            self.input.data.fill_(0)
            self.input.data[0].fill_(1)
            self.target.data.fill_(0)
            self.target.data[0].fill_(1)
        else:
            self.input.data.copy_(batch[0])
            self.target.data.copy_(batch[1])
            if self.inputMaskPredictor:
                self.input = self.inputMaskPredictor(self.input).detach()
            if self.targetMaskPredictor:
                self.target = self.targetMaskPredictor(self.target).detach()
        input_G = [self.input, self.noise]
        if self.gen_bis: # note this forward must come first, because we backprop Gforward_1
            self.noise.data.normal_(0, 1)
            gen1 = self.netG.forward(input_G).detach()
        else:
            gen1 = None

        def Dstep(x, y):
            out = self.netD.forward(x)
            res = self.netD.criterionD0(out[0], y)
            if self.netD.two_heads:
                res *= self.netD.weight_head0
                res += (1 - self.netD.weight_head0) * \
                        self.netD.criterionD1(out[1], y)
            return res, out

        # train D on real
        err_r, out = Dstep([self.input, self.target, gen1], self.r)
        p_real = out[0].mean()
        p_real_std = out[0].std()
        if set_ == 'train':
            self.netD.zero_grad()
            err_r.backward()
        # train D on fake
        self.noise.data.normal_(0, 1)
        self.gen0 = self.netG.forward(input_G)
        self.netD.apply(utils.disableBNRunningMeanStd)
        err_f, out = Dstep([self.input, self.gen0.detach(), gen1], self.f)
        self.netD.apply(utils.enableBNRunningMeanStd)
        p_fake = out[0].mean()
        p_fake_std = out[0].std()
        if set_ == 'train':
            err_f.backward()
            self.optimizerD.step()
            # train G on fake
            self.netG.zero_grad()
            self.noise.data.normal_(0, 1)
            err, out = Dstep([self.input, self.gen0, gen1], self.r)
            err.backward()
            self.optimizerG.step()

        mse = self.MSE.forward(self.gen0, self.target)
        out = {'err_r': err_r.data, 'err_f': err_f[0], 'mse': mse, \
                'p_real': p_real, 'p_fake': p_fake,\
                'p_real_std': p_real_std, 'p_fake_std': p_fake_std}
        return utils.to_number(out)
Beispiel #14
0
    def __parse_track_point(self, node):
        latitude = None
        if node.attributes.has_key('lat'):
            latitude = mod_utils.to_number(node.attributes['lat'].nodeValue)

        longitude = None
        if node.attributes.has_key('lon'):
            longitude = mod_utils.to_number(node.attributes['lon'].nodeValue)

        time_node = mod_utils.find_first_node(node, 'time')
        time = parse_time(self.get_node_data(time_node))

        elevation_node = mod_utils.find_first_node(node, 'ele')
        elevation = mod_utils.to_number(self.get_node_data(elevation_node))

        symbol_node = mod_utils.find_first_node(node, 'sym')
        symbol = self.get_node_data(symbol_node)

        comment_node = mod_utils.find_first_node(node, 'cmt')
        comment = self.get_node_data(comment_node)

        hdop_node = mod_utils.find_first_node(node, 'hdop')
        hdop = mod_utils.to_number(self.get_node_data(hdop_node))
		
        vdop_node = mod_utils.find_first_node(node, 'vdop')
        vdop = mod_utils.to_number(self.get_node_data(vdop_node))
		
        pdop_node = mod_utils.find_first_node(node, 'pdop')
        pdop = mod_utils.to_number(self.get_node_data(pdop_node))

        return mod_gpx.GPXTrackPoint(latitude=latitude, longitude=longitude, elevation=elevation, time=time,
                symbol=symbol, comment=comment, horizontal_dilution=hdop, vertical_dilution=vdop, 
                position_dilution=pdop)
Beispiel #15
0
def string_to_number(string, state):
    """
    @ = String

    Convert the `String` to a number. `String` can be of the form `<base>#<numeral>`
    where `base` can be from 2 (binary) to 16 (hexadecimal), or just `<numberal>`,
    where a base of 10 will be assumed. You can write numbers in your malang programs
    this way too.
    """
    assert_type(string, 'str', state)
    try:
        return Node('number', to_number(string.content))
    except ValueError:
        raise MalangError("Can't convert string to number", state)
Beispiel #16
0
def parse_collages(tree):
    table = tree.find_class('collage_table')
    if not len(table):
        raise Exception('could not find collage table')
    table = table[0]
    _, *rows = table.iterchildren()
    for row in rows:
        collage = {}
        columns = list(row)
        collage['category'] = columns[0].text_content().strip().lower()
        link = columns[1].find('a')
        collage['name'] = link.text_content().strip()
        url = link.attrib['href']
        collage['url'] = url
        p = urlparse.urlparse(url)
        collage['id'] = urlparse.parse_qs(p.query)['id'][0]
        collage['num_torrents'] = utils.to_number(columns[2].text_content())
        collage['num_subscribers'] = utils.to_number(columns[3].text_content())
        update_str = columns[4].find('span').attrib['title']
        # Can be parsed with
        #   datetime.strptime(update_str, '%b %d %Y, %H:%M')
        # but then can't dump to JSON, so leaving as string like this.
        collage['updated'] = update_str.strip().lower()
        yield collage
Beispiel #17
0
    def __parse_track_point_extension(self, node):
        node = self.xml_parser.get_first_child(node,
                                               "gpxtpx:TrackPointExtension")

        atemp_node = self.xml_parser.get_first_child(node, "gpxtpx:atemp")
        atemp = mod_utils.to_number(self.xml_parser.get_node_data(atemp_node),
                                    None)

        wtemp_node = self.xml_parser.get_first_child(node, "gpxtpx:wtemp")
        wtemp = mod_utils.to_number(self.xml_parser.get_node_data(wtemp_node),
                                    None)

        depth_node = self.xml_parser.get_first_child(node, "gpxtpx:depth")
        depth = mod_utils.to_number(self.xml_parser.get_node_data(depth_node),
                                    None)

        hr_node = self.xml_parser.get_first_child(node, "gpxtpx:hr")
        hr = mod_utils.to_number(self.xml_parser.get_node_data(hr_node), None)

        cad_node = self.xml_parser.get_first_child(node, "gpxtpx:cad")
        cad = mod_utils.to_number(self.xml_parser.get_node_data(cad_node),
                                  None)

        return mod_gpx.TrackPointExtensionv1(atemp, wtemp, depth, hr, cad)
Beispiel #18
0
    def __parse_track_point_extension(self, node):
        node = self.xml_parser.get_first_child(
            node, "gpxtpx:TrackPointExtension")

        atemp_node = self.xml_parser.get_first_child(node, "gpxtpx:atemp")
        atemp = mod_utils.to_number(
            self.xml_parser.get_node_data(atemp_node), None)

        wtemp_node = self.xml_parser.get_first_child(node, "gpxtpx:wtemp")
        wtemp = mod_utils.to_number(
            self.xml_parser.get_node_data(wtemp_node), None)

        depth_node = self.xml_parser.get_first_child(node, "gpxtpx:depth")
        depth = mod_utils.to_number(
            self.xml_parser.get_node_data(depth_node), None)

        hr_node = self.xml_parser.get_first_child(node, "gpxtpx:hr")
        hr = mod_utils.to_number(self.xml_parser.get_node_data(hr_node), None)

        cad_node = self.xml_parser.get_first_child(node, "gpxtpx:cad")
        cad = mod_utils.to_number(
            self.xml_parser.get_node_data(cad_node), None)

        return mod_gpx.TrackPointExtensionv1(atemp, wtemp, depth, hr, cad)
Beispiel #19
0
    def _parse_route_point(self, node):
        lat = self.xml_parser.get_node_attribute(node, 'lat')
        if not lat:
            raise mod_gpx.GPXException('Waypoint without latitude')

        lon = self.xml_parser.get_node_attribute(node, 'lon')
        if not lon:
            raise mod_gpx.GPXException('Waypoint without longitude')

        lat = mod_utils.to_number(lat)
        lon = mod_utils.to_number(lon)

        elevation_node = self.xml_parser.get_first_child(node, 'ele')
        elevation = mod_utils.to_number(
            self.xml_parser.get_node_data(elevation_node), None)

        time_node = self.xml_parser.get_first_child(node, 'time')
        time_str = self.xml_parser.get_node_data(time_node)
        time = parse_time(time_str)

        name_node = self.xml_parser.get_first_child(node, 'name')
        name = self.xml_parser.get_node_data(name_node)

        desc_node = self.xml_parser.get_first_child(node, 'desc')
        desc = self.xml_parser.get_node_data(desc_node)

        sym_node = self.xml_parser.get_first_child(node, 'sym')
        sym = self.xml_parser.get_node_data(sym_node)

        type_node = self.xml_parser.get_first_child(node, 'type')
        type = self.xml_parser.get_node_data(type_node)

        comment_node = self.xml_parser.get_first_child(node, 'cmt')
        comment = self.xml_parser.get_node_data(comment_node)

        hdop_node = self.xml_parser.get_first_child(node, 'hdop')
        hdop = mod_utils.to_number(self.xml_parser.get_node_data(hdop_node))

        vdop_node = self.xml_parser.get_first_child(node, 'vdop')
        vdop = mod_utils.to_number(self.xml_parser.get_node_data(vdop_node))

        pdop_node = self.xml_parser.get_first_child(node, 'pdop')
        pdop = mod_utils.to_number(self.xml_parser.get_node_data(pdop_node))

        return mod_gpx.GPXRoutePoint(lat,
                                     lon,
                                     elevation,
                                     time,
                                     name,
                                     desc,
                                     sym,
                                     type,
                                     comment,
                                     horizontal_dilution=hdop,
                                     vertical_dilution=vdop,
                                     position_dilution=pdop)
Beispiel #20
0
    def _parse_route_point(self, node):
        if not node.attributes.has_key("lat"):
            raise Exception("Waypoint without latitude")
        if not node.attributes.has_key("lon"):
            raise Exception("Waypoint without longitude")

        lat = mod_utils.to_number(node.attributes["lat"].nodeValue)
        lon = mod_utils.to_number(node.attributes["lon"].nodeValue)

        elevation_node = mod_utils.find_first_node(node, "ele")
        elevation = mod_utils.to_number(self.get_node_data(elevation_node), 0)

        time_node = mod_utils.find_first_node(node, "time")
        time_str = self.get_node_data(time_node)
        time = parse_time(time_str)

        name_node = mod_utils.find_first_node(node, "name")
        name = self.get_node_data(name_node)

        desc_node = mod_utils.find_first_node(node, "desc")
        desc = self.get_node_data(desc_node)

        sym_node = mod_utils.find_first_node(node, "sym")
        sym = self.get_node_data(sym_node)

        type_node = mod_utils.find_first_node(node, "type")
        type = self.get_node_data(type_node)

        comment_node = mod_utils.find_first_node(node, "cmt")
        comment = self.get_node_data(comment_node)

        hdop_node = mod_utils.find_first_node(node, "hdop")
        hdop = mod_utils.to_number(self.get_node_data(hdop_node))

        vdop_node = mod_utils.find_first_node(node, "vdop")
        vdop = mod_utils.to_number(self.get_node_data(vdop_node))

        pdop_node = mod_utils.find_first_node(node, "pdop")
        pdop = mod_utils.to_number(self.get_node_data(pdop_node))

        return mod_gpx.GPXRoutePoint(
            lat,
            lon,
            elevation,
            time,
            name,
            desc,
            sym,
            type,
            comment,
            horizontal_dilution=hdop,
            vertical_dilution=vdop,
            position_dilution=pdop,
        )
Beispiel #21
0
    def __parse_track_point(self, node):
        latitude = self.xml_parser.get_node_attribute(node, 'lat')
        if latitude:
            latitude = mod_utils.to_number(latitude)

        longitude = self.xml_parser.get_node_attribute(node, 'lon')
        if longitude:
            longitude = mod_utils.to_number(longitude)

        time_node = self.xml_parser.get_first_child(node, 'time')
        time_str = self.xml_parser.get_node_data(time_node)
        time = parse_time(time_str)

        elevation_node = self.xml_parser.get_first_child(node, 'ele')
        elevation = mod_utils.to_number(
            self.xml_parser.get_node_data(elevation_node), None)

        sym_node = self.xml_parser.get_first_child(node, 'sym')
        symbol = self.xml_parser.get_node_data(sym_node)

        comment_node = self.xml_parser.get_first_child(node, 'cmt')
        comment = self.xml_parser.get_node_data(comment_node)

        hdop_node = self.xml_parser.get_first_child(node, 'hdop')
        hdop = mod_utils.to_number(self.xml_parser.get_node_data(hdop_node))

        vdop_node = self.xml_parser.get_first_child(node, 'vdop')
        vdop = mod_utils.to_number(self.xml_parser.get_node_data(vdop_node))

        pdop_node = self.xml_parser.get_first_child(node, 'pdop')
        pdop = mod_utils.to_number(self.xml_parser.get_node_data(pdop_node))

        speed_node = self.xml_parser.get_first_child(node, 'speed')
        speed = mod_utils.to_number(self.xml_parser.get_node_data(speed_node))

        extension_node = self.xml_parser.get_first_child(node, 'extensions')
        extensions = self.__parse_track_point_extension(extension_node)

        return mod_gpx.GPXTrackPoint(latitude=latitude,
                                     longitude=longitude,
                                     elevation=elevation,
                                     time=time,
                                     symbol=symbol,
                                     comment=comment,
                                     horizontal_dilution=hdop,
                                     vertical_dilution=vdop,
                                     position_dilution=pdop,
                                     speed=speed,
                                     extensions=extensions)
    def _parse_waypoint(self, node):
        if not node.attributes.has_key('lat'):
            raise mod_gpx.GPXException('Waypoint without latitude')
        if not node.attributes.has_key('lon'):
            raise mod_gpx.GPXException('Waypoint without longitude')

        lat = mod_utils.to_number(node.attributes['lat'].nodeValue)
        lon = mod_utils.to_number(node.attributes['lon'].nodeValue)

        elevation_node = mod_utils.find_first_node(node, 'ele')
        elevation = mod_utils.to_number(self.get_node_data(elevation_node), 0)

        time_node = mod_utils.find_first_node(node, 'time')
        time_str = self.get_node_data(time_node)
        time = parse_time(time_str)

        name_node = mod_utils.find_first_node(node, 'name')
        name = self.get_node_data(name_node)

        desc_node = mod_utils.find_first_node(node, 'desc')
        desc = self.get_node_data(desc_node)

        sym_node = mod_utils.find_first_node(node, 'sym')
        sym = self.get_node_data(sym_node)

        type_node = mod_utils.find_first_node(node, 'type')
        type = self.get_node_data(type_node)

        comment_node = mod_utils.find_first_node(node, 'cmt')
        comment = self.get_node_data(comment_node)

        hdop_node = mod_utils.find_first_node(node, 'hdop')
        hdop = mod_utils.to_number(self.get_node_data(hdop_node))

        vdop_node = mod_utils.find_first_node(node, 'vdop')
        vdop = mod_utils.to_number(self.get_node_data(vdop_node))

        pdop_node = mod_utils.find_first_node(node, 'pdop')
        pdop = mod_utils.to_number(self.get_node_data(pdop_node))

        return mod_gpx.GPXWaypoint(latitude=lat,
                                   longitude=lon,
                                   elevation=elevation,
                                   time=time,
                                   name=name,
                                   description=desc,
                                   symbol=sym,
                                   type=type,
                                   comment=comment,
                                   horizontal_dilution=hdop,
                                   vertical_dilution=vdop,
                                   position_dilution=pdop)
Beispiel #23
0
    def __parse_track(self, node):
        name_node = mod_utils.find_first_node(node, mod_utils.tag('name',self.ns))
        name = self.get_node_data(name_node)

        description_node = mod_utils.find_first_node(node, mod_utils.tag('desc',self.ns))
        description = self.get_node_data(description_node)

        number_node = mod_utils.find_first_node(node, mod_utils.tag('number',self.ns))
        number = mod_utils.to_number(self.get_node_data(number_node))

        track = mod_gpx.GPXTrack(name, description, number)

        child_nodes = node.getchildren()
        for child_node in child_nodes:
            if child_node.tag == mod_utils.tag('trkseg',self.ns):
                track_segment = self.__parse_track_segment(child_node)
                track.segments.append(track_segment)

        return track
Beispiel #24
0
    def _parse_route(self, node):
        name_node = mod_utils.find_first_node(node, mod_utils.tag('name',self.ns))
        name = self.get_node_data(name_node)

        description_node = mod_utils.find_first_node(node, mod_utils.tag('desc',self.ns))
        description = self.get_node_data(description_node)

        number_node = mod_utils.find_first_node(node, mod_utils.tag('number',self.ns))
        number = mod_utils.to_number(self.get_node_data(number_node))

        route = mod_gpx.GPXRoute(name, description, number)

        child_nodes = node.getchildren()
        for child_node in child_nodes:
            if child_node.tag == mod_utils.tag('rtept',self.ns):
                route_point = self._parse_route_point(child_node)
                route.points.append(route_point)

        return route
Beispiel #25
0
    def gen_update(self, x_in, x_sm, param):
        self.gen_opt.zero_grad()

        _, _, pred_sem, _ = self.generator(x_in)

        x_sm = x_sm.squeeze(1)
        self.loss_semantic = self.semantic_criterion(pred_sem, x_sm)
        pred_sm = torch.argmax(pred_sem[0], dim=0)
        self.loss_sem_acc = float(to_number(
            torch.sum(x_sm[0] == pred_sm))) / (x_sm.shape[1] * x_sm.shape[2])
        self.loss_sem_miou, self.sem_iou = compute_miou(pred_sm, x_sm)

        loss_sem = param['semantic_w'] * self.loss_semantic

        # total loss
        self.loss_total = loss_sem

        self.loss_total.backward()
        self.gen_opt.step()
Beispiel #26
0
    def _parse_waypoint(self, node):
        lat = self.xml_parser.get_node_attribute(node, 'lat')
        if not lat:
            raise mod_gpx.GPXException('Waypoint without latitude')

        lon = self.xml_parser.get_node_attribute(node, 'lon')
        if not lon:
            raise mod_gpx.GPXException('Waypoint without longitude')

        lat = mod_utils.to_number(lat)
        lon = mod_utils.to_number(lon)

        elevation_node = self.xml_parser.get_first_child(node, 'ele')
        elevation = mod_utils.to_number(
            self.xml_parser.get_node_data(elevation_node), None)

        time_node = self.xml_parser.get_first_child(node, 'time')
        time_str = self.xml_parser.get_node_data(time_node)
        time = parse_time(time_str)

        name_node = self.xml_parser.get_first_child(node, 'name')
        name = self.xml_parser.get_node_data(name_node)

        desc_node = self.xml_parser.get_first_child(node, 'desc')
        desc = self.xml_parser.get_node_data(desc_node)

        sym_node = self.xml_parser.get_first_child(node, 'sym')
        sym = self.xml_parser.get_node_data(sym_node)

        type_node = self.xml_parser.get_first_child(node, 'type')
        type = self.xml_parser.get_node_data(type_node)

        comment_node = self.xml_parser.get_first_child(node, 'cmt')
        comment = self.xml_parser.get_node_data(comment_node)

        hdop_node = self.xml_parser.get_first_child(node, 'hdop')
        hdop = mod_utils.to_number(self.xml_parser.get_node_data(hdop_node))

        vdop_node = self.xml_parser.get_first_child(node, 'vdop')
        vdop = mod_utils.to_number(self.xml_parser.get_node_data(vdop_node))

        pdop_node = self.xml_parser.get_first_child(node, 'pdop')
        pdop = mod_utils.to_number(self.xml_parser.get_node_data(pdop_node))

        return mod_gpx.GPXWaypoint(
            latitude=lat, longitude=lon, elevation=elevation,
            time=time, name=name, description=desc, symbol=sym,
            type=type, comment=comment, horizontal_dilution=hdop,
            vertical_dilution=vdop, position_dilution=pdop)
Beispiel #27
0
    def __parse_track(self, node):
        name_node = self.xml_parser.get_first_child(node, 'name')
        name = self.xml_parser.get_node_data(name_node)

        description_node = self.xml_parser.get_first_child(node, 'desc')
        description = self.xml_parser.get_node_data(description_node)

        number_node = self.xml_parser.get_first_child(node, 'number')
        number = mod_utils.to_number(
            self.xml_parser.get_node_data(number_node))

        track = mod_gpx.GPXTrack(name, description, number)

        child_nodes = self.xml_parser.get_children(node)
        for child_node in child_nodes:
            if self.xml_parser.get_node_name(child_node) == 'trkseg':
                track_segment = self.__parse_track_segment(child_node)
                track.segments.append(track_segment)

        return track
Beispiel #28
0
    def _parse_route(self, node):
        name_node = self.xml_parser.get_first_child(node, 'name')
        name = self.xml_parser.get_node_data(name_node)

        description_node = self.xml_parser.get_first_child(node, 'desc')
        description = self.xml_parser.get_node_data(description_node)

        number_node = self.xml_parser.get_first_child(node, 'number')
        number = mod_utils.to_number(
            self.xml_parser.get_node_data(number_node))

        route = mod_gpx.GPXRoute(name, description, number)

        child_nodes = self.xml_parser.get_children(node)
        for child_node in child_nodes:
            if self.xml_parser.get_node_name(child_node) == 'rtept':
                route_point = self._parse_route_point(child_node)
                route.points.append(route_point)

        return route
Beispiel #29
0
    def __parse_track(self, node):
        name_node = self.xml_parser.get_first_child(node, 'name')
        name = self.xml_parser.get_node_data(name_node)

        description_node = self.xml_parser.get_first_child(node, 'desc')
        description = self.xml_parser.get_node_data(description_node)

        number_node = self.xml_parser.get_first_child(node, 'number')
        number = mod_utils.to_number(
            self.xml_parser.get_node_data(number_node))

        track = mod_gpx.GPXTrack(name, description, number)

        child_nodes = self.xml_parser.get_children(node)
        for child_node in child_nodes:
            if self.xml_parser.get_node_name(child_node) == 'trkseg':
                track_segment = self.__parse_track_segment(child_node)
                track.segments.append(track_segment)

        return track
    def __parse_track(self, node):
        name_node = mod_utils.find_first_node(node, 'name')
        name = self.get_node_data(name_node)

        description_node = mod_utils.find_first_node(node, 'desc')
        description = self.get_node_data(description_node)

        number_node = mod_utils.find_first_node(node, 'number')
        number = mod_utils.to_number(self.get_node_data(number_node))

        track = mod_gpx.GPXTrack(name, description, number)

        child_nodes = node.childNodes
        for child_node in child_nodes:
            if child_node.nodeName == 'trkseg':
                track_segment = self.__parse_track_segment(child_node)

                track.segments.append(track_segment)

        return track
    def _parse_route(self, node):
        name_node = mod_utils.find_first_node(node, 'name')
        name = self.get_node_data(name_node)

        description_node = mod_utils.find_first_node(node, 'desc')
        description = self.get_node_data(description_node)

        number_node = mod_utils.find_first_node(node, 'number')
        number = mod_utils.to_number(self.get_node_data(number_node))

        route = mod_gpx.GPXRoute(name, description, number)

        child_nodes = node.childNodes
        for child_node in child_nodes:
            node_name = child_node.nodeName
            if node_name == 'rtept':
                route_point = self._parse_route_point(child_node)
                route.points.append(route_point)

        return route
Beispiel #32
0
    def _parse_route(self, node):
        name_node = self.xml_parser.get_first_child(node, 'name')
        name = self.xml_parser.get_node_data(name_node)

        description_node = self.xml_parser.get_first_child(node, 'desc')
        description = self.xml_parser.get_node_data(description_node)

        number_node = self.xml_parser.get_first_child(node, 'number')
        number = mod_utils.to_number(
            self.xml_parser.get_node_data(number_node))

        route = mod_gpx.GPXRoute(name, description, number)

        child_nodes = self.xml_parser.get_children(node)
        for child_node in child_nodes:
            if self.xml_parser.get_node_name(child_node) == 'rtept':
                route_point = self._parse_route_point(child_node)
                route.points.append(route_point)

        return route
Beispiel #33
0
    def _parse_route(self, node):
        name_node = mod_utils.find_first_node(node, "name")
        name = self.get_node_data(name_node)

        description_node = mod_utils.find_first_node(node, "desc")
        description = self.get_node_data(description_node)

        number_node = mod_utils.find_first_node(node, "number")
        number = mod_utils.to_number(self.get_node_data(number_node))

        route = mod_gpx.GPXRoute(name, description, number)

        child_nodes = node.childNodes
        for child_node in child_nodes:
            node_name = child_node.nodeName
            if node_name == "rtept":
                route_point = self._parse_route_point(child_node)
                route.points.append(route_point)

        return route
Beispiel #34
0
    def __parse_track(self, node):
        name_node = mod_utils.find_first_node(node, "name")
        name = self.get_node_data(name_node)

        description_node = mod_utils.find_first_node(node, "desc")
        description = self.get_node_data(description_node)

        number_node = mod_utils.find_first_node(node, "number")
        number = mod_utils.to_number(self.get_node_data(number_node))

        track = mod_gpx.GPXTrack(name, description, number)

        child_nodes = node.childNodes
        for child_node in child_nodes:
            if child_node.nodeName == "trkseg":
                track_segment = self.__parse_track_segment(child_node)

                track.segments.append(track_segment)

        return track
Beispiel #35
0
    def __parse_track_point(self, node):
        latitude = self.xml_parser.get_node_attribute(node, 'lat')
        if latitude:
            latitude = mod_utils.to_number(latitude)

        longitude = self.xml_parser.get_node_attribute(node, 'lon')
        if longitude:
            longitude = mod_utils.to_number(longitude)

        time_node = self.xml_parser.get_first_child(node, 'time')
        time_str = self.xml_parser.get_node_data(time_node)
        time = parse_time(time_str)

        elevation_node = self.xml_parser.get_first_child(node, 'ele')
        elevation = mod_utils.to_number(
            self.xml_parser.get_node_data(elevation_node), None)

        sym_node = self.xml_parser.get_first_child(node, 'sym')
        symbol = self.xml_parser.get_node_data(sym_node)

        comment_node = self.xml_parser.get_first_child(node, 'cmt')
        comment = self.xml_parser.get_node_data(comment_node)

        hdop_node = self.xml_parser.get_first_child(node, 'hdop')
        hdop = mod_utils.to_number(self.xml_parser.get_node_data(hdop_node))

        vdop_node = self.xml_parser.get_first_child(node, 'vdop')
        vdop = mod_utils.to_number(self.xml_parser.get_node_data(vdop_node))

        pdop_node = self.xml_parser.get_first_child(node, 'pdop')
        pdop = mod_utils.to_number(self.xml_parser.get_node_data(pdop_node))

        speed_node = self.xml_parser.get_first_child(node, 'speed')
        speed = mod_utils.to_number(self.xml_parser.get_node_data(speed_node))

        extension_node = self.xml_parser.get_first_child(node, 'extensions')
        extensions = self.__parse_track_point_extension(extension_node)

        return mod_gpx.GPXTrackPoint(
            latitude=latitude, longitude=longitude, elevation=elevation, time=time,
            symbol=symbol, comment=comment, horizontal_dilution=hdop, vertical_dilution=vdop,
            position_dilution=pdop, speed=speed, extensions=extensions)
Beispiel #36
0
    def _parse_waypoint(self, node):
        if not node.attrib.get('lat'):
            raise mod_gpx.GPXException('Waypoint without latitude')
        if not node.attrib.get('lon'):
            raise mod_gpx.GPXException('Waypoint without longitude')

        lat = mod_utils.to_number(node.attrib.get('lat'))
        lon = mod_utils.to_number(node.attrib.get('lon'))

        elevation_node = mod_utils.find_first_node(node, mod_utils.tag('ele',self.ns))
        elevation = mod_utils.to_number(self.get_node_data(elevation_node), 0)

        time_node = mod_utils.find_first_node(node, mod_utils.tag('time',self.ns))
        time_str = self.get_node_data(time_node)
        time = parse_time(time_str)

        name_node = mod_utils.find_first_node(node, mod_utils.tag('name',self.ns))
        name = self.get_node_data(name_node)

        desc_node = mod_utils.find_first_node(node, mod_utils.tag('desc',self.ns))
        desc = self.get_node_data(desc_node)

        sym_node = mod_utils.find_first_node(node, mod_utils.tag('sym',self.ns))
        sym = self.get_node_data(sym_node)

        type_node = mod_utils.find_first_node(node, mod_utils.tag('type',self.ns))
        type = self.get_node_data(type_node)

        comment_node = mod_utils.find_first_node(node, mod_utils.tag('cmt',self.ns))
        comment = self.get_node_data(comment_node)

        hdop_node = mod_utils.find_first_node(node, mod_utils.tag('hdop',self.ns))
        hdop = mod_utils.to_number(self.get_node_data(hdop_node))

        vdop_node = mod_utils.find_first_node(node, mod_utils.tag('vdop',self.ns))
        vdop = mod_utils.to_number(self.get_node_data(vdop_node))

        pdop_node = mod_utils.find_first_node(node, mod_utils.tag('pdop',self.ns))
        pdop = mod_utils.to_number(self.get_node_data(pdop_node))

        return mod_gpx.GPXWaypoint(latitude=lat, longitude=lon, elevation=elevation,
            time=time, name=name, description=desc, symbol=sym,
            type=type, comment=comment, horizontal_dilution=hdop,
            vertical_dilution=vdop, position_dilution=pdop)
Beispiel #37
0
    def _parse_route_point(self, node):
        if not node.attributes.has_key('lat'):
            raise mod_gpx.GPXException('Waypoint without latitude')
        if not node.attributes.has_key('lon'):
            raise mod_gpx.GPXException('Waypoint without longitude')

        lat = mod_utils.to_number(node.attributes['lat'].nodeValue)
        lon = mod_utils.to_number(node.attributes['lon'].nodeValue)

        elevation_node = mod_utils.find_first_node(node, 'ele')
        elevation = mod_utils.to_number(self.get_node_data(elevation_node), 0)

        time_node = mod_utils.find_first_node(node, 'time')
        time_str = self.get_node_data(time_node)
        time = parse_time(time_str)

        name_node = mod_utils.find_first_node(node, 'name')
        name = self.get_node_data(name_node)

        desc_node = mod_utils.find_first_node(node, 'desc')
        desc = self.get_node_data(desc_node)

        sym_node = mod_utils.find_first_node(node, 'sym')
        sym = self.get_node_data(sym_node)

        type_node = mod_utils.find_first_node(node, 'type')
        type = self.get_node_data(type_node)

        comment_node = mod_utils.find_first_node(node, 'cmt')
        comment = self.get_node_data(comment_node)

        hdop_node = mod_utils.find_first_node(node, 'hdop')
        hdop = mod_utils.to_number(self.get_node_data(hdop_node))
		
        vdop_node = mod_utils.find_first_node(node, 'vdop')
        vdop = mod_utils.to_number(self.get_node_data(vdop_node))
		
        pdop_node = mod_utils.find_first_node(node, 'pdop')
        pdop = mod_utils.to_number(self.get_node_data(pdop_node))

        return mod_gpx.GPXRoutePoint(lat, lon, elevation, time, name, desc, sym, type, comment,
                horizontal_dilution = hdop, vertical_dilution = vdop, position_dilution = pdop)
Beispiel #38
0
    def __parse_track_point(self, node):
        latitude = None
        if node.attrib.get('lat'):
            latitude = mod_utils.to_number(node.attrib.get('lat'))

        longitude = None
        if node.attrib.get('lon'):
            longitude = mod_utils.to_number(node.attrib.get('lon'))

        time_node = mod_utils.find_first_node(node, mod_utils.tag('time',self.ns))
        time_str = self.get_node_data(time_node)
        time = parse_time(time_str)

        elevation_node = mod_utils.find_first_node(node, mod_utils.tag('ele',self.ns))
        elevation = mod_utils.to_number(self.get_node_data(elevation_node), 0)

        sym_node = mod_utils.find_first_node(node, mod_utils.tag('sym',self.ns))
        symbol = self.get_node_data(sym_node)

        comment_node = mod_utils.find_first_node(node, mod_utils.tag('cmt',self.ns))
        comment = self.get_node_data(comment_node)

        hdop_node = mod_utils.find_first_node(node, mod_utils.tag('hdop',self.ns))
        hdop = mod_utils.to_number(self.get_node_data(hdop_node))

        vdop_node = mod_utils.find_first_node(node, mod_utils.tag('vdop',self.ns))
        vdop = mod_utils.to_number(self.get_node_data(vdop_node))

        pdop_node = mod_utils.find_first_node(node, mod_utils.tag('pdop',self.ns))
        pdop = mod_utils.to_number(self.get_node_data(pdop_node))

        speed_node = mod_utils.find_first_node(node, mod_utils.tag('speed',self.ns))
        speed = mod_utils.to_number(self.get_node_data(speed_node))

        return mod_gpx.GPXTrackPoint(latitude=latitude, longitude=longitude, elevation=elevation, time=time,
            symbol=symbol, comment=comment, horizontal_dilution=hdop, vertical_dilution=vdop,
            position_dilution=pdop, speed=speed)
Beispiel #39
0
    def __parse_track_point(self, node):
        latitude = None
        if node.attributes.has_key("lat"):
            latitude = mod_utils.to_number(node.attributes["lat"].nodeValue)

        longitude = None
        if node.attributes.has_key("lon"):
            longitude = mod_utils.to_number(node.attributes["lon"].nodeValue)

        time_node = mod_utils.find_first_node(node, "time")
        time = parse_time(self.get_node_data(time_node))

        elevation_node = mod_utils.find_first_node(node, "ele")
        elevation = mod_utils.to_number(self.get_node_data(elevation_node))

        symbol_node = mod_utils.find_first_node(node, "sym")
        symbol = self.get_node_data(symbol_node)

        comment_node = mod_utils.find_first_node(node, "cmt")
        comment = self.get_node_data(comment_node)

        hdop_node = mod_utils.find_first_node(node, "hdop")
        hdop = mod_utils.to_number(self.get_node_data(hdop_node))

        vdop_node = mod_utils.find_first_node(node, "vdop")
        vdop = mod_utils.to_number(self.get_node_data(vdop_node))

        pdop_node = mod_utils.find_first_node(node, "pdop")
        pdop = mod_utils.to_number(self.get_node_data(pdop_node))

        return mod_gpx.GPXTrackPoint(
            latitude=latitude,
            longitude=longitude,
            elevation=elevation,
            time=time,
            symbol=symbol,
            comment=comment,
            horizontal_dilution=hdop,
            vertical_dilution=vdop,
            position_dilution=pdop,
        )
Beispiel #40
0
def test_to_number(string_repr, expected):
    assert to_number(string_repr) == expected
Beispiel #41
0
 def print_loss(self):
     info = 'Loss: B-vgg: {:.4f} | B-pixel: {:.4f} | B-retina: {:.4f} | B-gen: {:.4f} | B-dis: {:.4f} | ' \
            'B-sem_acc: {:.4f} | B-sem_miou: {:.4f} | B-ce_loss: {:.4f} | R-vgg: {:.4f} | R-pixel: {:.4f} | ' \
            'R-retina: {:.4f} | R-gen: {:.4f} | R-dis: {:.4f}'.format(
                to_number(self.loss_percep_bg),
                to_number(self.loss_pixel_bg),
                to_number(self.loss_retina_bg),
                to_number(self.loss_gen_bg),
                to_number(self.loss_dis_bg),
                to_number(self.loss_sem_acc),
                to_number(self.loss_sem_miou),
                to_number(self.loss_semantic),
                to_number(self.loss_vgg_rf),
                to_number(self.loss_pixel_rf),
                to_number(self.loss_retina_rf),
                to_number(self.loss_gen_rf),
                to_number(self.loss_dis_rf))
     return info
Beispiel #42
0
 def print_loss(self):
     info = 'Loss: {:.4f}'.format(to_number(self.loss))
     return info
Beispiel #43
0
        # cv2.waitKey()
        #
        # continue

        # trainer.dis_update(images_in, images_out, config)
        trainer.gen_update(images_in, images_out, config)

        # Dump training stats in log file
        # if (iterations + 1) % config['log_iter'] == 0:
        #     print('<{}> [Epoch: {}] [Iter: {}/{}] | Loss: {}'.format(get_local_time(), epoch, it, len(train_loader),
        #                                                              to_number(trainer.loss_total)))
        if (iterations + 1) % config['log_iter'] == 0:
            print(
                '<{}> [Epoch: {}] [Iter: {}/{}] | [Loss] Pixel: {}, Pair: {}, GT: {}, Total: {}'
                .format(get_local_time(), epoch, it, len(train_loader),
                        to_number(trainer.loss_pixel),
                        to_number(trainer.loss_pair),
                        to_number(trainer.loss_gt),
                        to_number(trainer.loss_total)))
            write_loss(iterations, trainer, train_writer)

        # Write images
        # if (iterations + 1) % config['image_save_iter'] == 0:
        #     with torch.no_grad():
        #         outputs = trainer.sample(images_in, images_out)
        #     # write_2images(outputs, display_size, image_directory, 'train_%08d' % (iterations + 1))
        #     # HTML
        #     write_html(output_directory + "/index.html", iterations + 1, config['image_save_iter'], 'images')

        iterations += 1