Esempio n. 1
0
    def predict(self, data):
        """Predict objects from data."""
        with torch.no_grad():
            # image = transforms.Image.open(data)
            image = data
            image_tensor, scale = self.dataset_class.preprocess(
                image, Config.IMAGE_MIN_SIDE, Config.IMAGE_MAX_SIDE)

            self.logger.debug("Ok predicting from %s", image)
            detection_bboxes, detection_classes, detection_probs, _ = self.model.eval(
            ).forward(image_tensor.unsqueeze(dim=0).cpu())
            detection_bboxes /= scale

            self.logger.debug("Bboxes %s", detection_bboxes)
            self.logger.debug("Classes %s", detection_classes)
            self.logger.debug("Probs %s", detection_probs)
            self.logger.debug("Probs distribution %s",
                              sparklines(detection_probs.tolist()))
            probs_freq, probs_bins = np.histogram(detection_probs.tolist(),
                                                  range=(0, 1))
            self.logger.debug("Histogram of probs distribution %d %s %d",
                              probs_bins[0], sparklines(probs_freq),
                              probs_bins[-1])
            self.logger.debug(
                "Pruned Histogram of probs distribution %d %s %d",
                probs_bins[1], sparklines(probs_freq[1:]), probs_bins[-1])

            # Some bboxes might have nan coordinates; prune them
            # TODO: Is this still so?
            mask = ~np.isnan(detection_bboxes).any(axis=1).bool()
            self.logger.debug("Pruned from %d to %d bboxes",
                              len(detection_bboxes), sum(mask))

            return detection_bboxes[mask], detection_classes[
                mask], detection_probs[mask]
Esempio n. 2
0
def test_gaps():
    res = sparklines([1, None, 1, 2])
    exp = ["▁ ▁█"]
    assert exp == res
    res = sparklines([1, None, 1])
    exp = ["▄ ▄"]
    assert exp == res, (exp, res)
Esempio n. 3
0
def test_wrap_consistency():
    res = sparklines([1,2, 3, 1, 2, 3, 1, 2], wrap=3)
    exp = (
        sparklines([1, 2, 3], maximum=3, minimum=1)
        + ['']
        + sparklines([1, 2, 3], maximum=3, minimum=1)
        + ['']
        + sparklines([1, 2], maximum=3, minimum=1))
    assert res == exp
def sparkline_sizes(sizes: List) -> str:
    # sizes is sorted so we can take advantage of that to accelerate things
    median = statistics.median_low(sizes)
    bucket_size = 2
    top_bucket = 2 * median  # up to median there's half of the items. Since that's typically a short range anyway, let's show twice that.
    buckets_maxcontent = range(
        2, top_bucket,
        bucket_size)  # each bucket contains values up to this, inclusive
    if len(buckets_maxcontent) == 0:
        logging.info(
            f"Can't bucketize, moving on. sizes={sizes}, median={median}, block={block}"
        )
        return f"CAN'T BUCKETIZE! sizes={sizes}"
    buckets_contents = [0 for b in buckets_maxcontent]
    maxbucket = len(buckets_maxcontent)
    count = 0
    for s in sizes:
        i = math.ceil(s / bucket_size)
        if i >= maxbucket:
            break
        count += 1
        i = clamp(i, 0, len(buckets_contents) - 1)
        buckets_contents[i] += 1

    sl = sparklines(buckets_contents)[0]
    remaining = (1 - count / len(sizes)) * 100
    line = f"median={median}\t\t{buckets_maxcontent[0]}{sl}{buckets_maxcontent[-1]} (+{remaining:.0f}% more)"
    return line
Esempio n. 5
0
def test1():
    "Test single values all have the same four pixel high output character."

    for i in range(10):
        res = sparklines([i])
        exp = ['▄']
        assert res == exp
Esempio n. 6
0
def test_empty():
    "Make sure degenerate cases don't fail"
    res = sparklines([])
    exp = ['']
    # Produces an empty line from the command line
    #   we might prefer empty output
    assert res == exp
Esempio n. 7
0
    def get_summary_data(self, metric_data, ident, index):
        value_rank = self.rank(metric_data, ident=None, index=index)
        is_best = value_rank == 0
        is_first = self._ts_store.num_values(metric_data) == 1
        runl = self.run_length(metric_data)
        is_broken_run = not is_first and runl < 2
        quantile_value = self.quantile(metric_data, index=index)

        timeseries = self.get_timeseries(metric_data, ident, index, 10)
        sparkline = sparklines.sparklines(timeseries)[0]
        mean_value = self.mean(metric_data)
        num_values = self._ts_store.num_values(metric_data)

        if self._ts_store.check_if_empty(metric_data):
            current_value = None
        else:
            current_value = self._ts_store.get_value(metric_data,
                                                     ident,
                                                     index=index)

        return dict(mean=mean_value,
                    best=self.best(metric_data),
                    is_best=is_best,
                    is_first=is_first,
                    num_values=num_values,
                    run_length=runl,
                    rank=value_rank,
                    is_broken_run=is_broken_run,
                    quantile=quantile_value,
                    sparkline=sparkline,
                    timeseries=timeseries,
                    best_ratio=self.best_ratio(metric_data, index=index),
                    value=current_value)
Esempio n. 8
0
def test_multiline():
    res = sparklines([1, 5, 8], num_lines=3)
    exp = [
        "  █",
        " ▆█",
        "▁██"]
    assert res == exp
Esempio n. 9
0
 def get(self):
     """Return the sparkline."""
     ret = sparklines(self.percents)[0]
     if self.__with_text:
         percents_without_none = [x for x in self.percents if x is not None]
         if len(percents_without_none) > 0:
             ret = '{}{:5.1f}%'.format(ret, percents_without_none[-1])
     return nativestr(ret)
Esempio n. 10
0
def DrawGraph(title, y_data):
    win.addch('\n')
    win.addstr(title)
    y = gpuDevices[i].gpu_usage
    line = sparklines(y, num_lines=2, minimum=0, maximum=100)
    win.addstr(line[0])
    win.addch('\n')
    win.addstr('%3d %%  ' % gpuDevices[i].gpu_usage[index])
    win.addstr(line[1])
Esempio n. 11
0
    def print_stats_for(name, values):
        from statistics import mean, harmonic_mean, median

        click.echo(click.style(
            '🔢 {}: count={} min={} max={} mean={:.1f} harmonic_mean={:.1f} median={:.1f}'.format(
                name.ljust(16), len(values), min(values), max(values),
                mean(values), harmonic_mean(
                    values), median(values)
            ), fg='magenta'))

        # make a tiny histo
        from sparklines import sparklines
        import numpy as np
        hist, _ = np.histogram(values, bins=range(15))
        if hist.sum() > 0:
            hist = [Deleter.zero_to_none(v) for v in list(hist)]

            for line in sparklines(hist):
                click.echo(click.style(
                    '📈 {}: {} {} {}'.format(
                        (name + ' histo').ljust(16), min(values), line, max(values)
                    ), fg='magenta'))
Esempio n. 12
0
def display_training_summary(average_return_per_episode,
                             average_frames_per_episode, total_frames, fps):
    total_frames_display = "{:,}".format(total_frames)
    fps_display = "{:,}".format(round(fps))
    latest_average_return = round(average_return_per_episode[-1], 2)
    latest_average_frames = average_frames_per_episode[-1]
    return_lines = sparklines(average_return_per_episode[-80:],
                              num_lines=RETURN_GRAPH_HEIGHT)

    if CLEAR_ON_LOG:
        os.system('cls' if os.name == 'nt' else 'clear')

    print(
        '%s Frames | %s FPS | \33[7m %.2f Avg Episode Return \033[0m | %i Avg Frames / Episode'
        % (total_frames_display, fps_display, latest_average_return,
           latest_average_frames))

    print('\33[90m')
    print('Average Return')
    for line in return_lines:
        print(line)
    print('\033[0m')
Esempio n. 13
0
    def print_stats_for(name, values):
        from statistics import mean, harmonic_mean, median

        if not values or len(values) == 0:
            # skip because it's empty
            return

        click.echo(
            click.style(
                "🔢 {}: count={} min={} max={} mean={:.1f} harmonic_mean={:.1f} median={:.1f}".format(
                    name.ljust(16),
                    len(values),
                    min(values),
                    max(values),
                    mean(values),
                    harmonic_mean(values),
                    median(values),
                ),
                fg="magenta",
            )
        )

        # make a tiny histo
        from sparklines import sparklines
        import numpy as np

        hist, _ = np.histogram(values, bins=range(15))
        if hist.sum() > 0:
            hist = [Deleter.zero_to_none(v) for v in list(hist)]

            for line in sparklines(hist):
                click.echo(
                    click.style(
                        "📈 {}: {} {} {}".format(
                            (name + " histo").ljust(16), min(values), line, max(values)
                        ),
                        fg="magenta",
                    )
                )
Esempio n. 14
0
 def get_lines(self):
     value = self.value - self.min()
     lo, hi = value.min(), value.max()
     return [sparklines(x, minimum=lo, maximum=hi) for x in value]
Esempio n. 15
0
def test_wrap_scale():
    res = sparklines([100, 50, 100, 20, 50, 20, 1, 1, 1], wrap=3)
    exp = ["█▄█", "", "▂▄▂", "", "▁▁▁"]
    assert res == exp
Esempio n. 16
0
def test_wrap():
    res = sparklines([1,2, 3, 1, 2, 3, 1, 2], wrap=3)
    exp = ["▁▄█", "", "▁▄█", "", "▁▄"]
    assert res == exp
Esempio n. 17
0
 def print_graph(self, data, title="", x0="0", x1=None):
     for i, line in enumerate(sparklines(data, num_lines=2)):
         if i != 1:
             print(f"{'':>15}  {' ' * len(x0)} {line} {' ' * len(x1)}")
         else:
             print(f"{title:>15}: {x0} {line} {x1}")
Esempio n. 18
0
def test_minimum_internal_consistency():
    res = sparklines([0, 0, 11, 12, 13], minimum=10)
    exp = sparklines([10, 10, 11, 12, 13], minimum=10)
    assert res == exp
Esempio n. 19
0
def test_minimum():
    res = sparklines([0, 0, 11, 12, 13], minimum=10)
    exp = ['▁▁▃▆█']
    assert res == exp
Esempio n. 20
0
def _sparklines(arr: list) -> str:
    return ''.join([x for x in sparklines(arr)])
Esempio n. 21
0
def test_minmax():
    "Test two values, min and max."

    res = sparklines([1, 8])
    exp = ['▁█'] # 1, 8
    assert res == exp
Esempio n. 22
0
def sparkline_str(x):
    bins = np.histogram(x)[0]
    sl = ''.join(sparklines(bins))
    return sl
Esempio n. 23
0
def test_wrap_escaping_consistency():
    no_emph = sparklines([1,2, 3, 1, 2, 3, 1, 2], wrap=3)
    stripped_emph = map(strip_ansi, sparklines([1,2, 3, 1, 2, 3, 1, 2], wrap=3, emph=['green:le:1.0']))
    assert no_emph == list(stripped_emph)
Esempio n. 24
0
def timespark(values):
    """Draw a one-line Unicode sparkline plot of a sequence of
    reverse-chronological values.
    """
    return sparklines(list(reversed(list(values))))[0]
Esempio n. 25
0
def _test_wrap_escaping():
    res = sparklines([1, 10, 1, 10, 1, 10], emph=['green:ge:2.0'], wrap=3)
    exp = ["\x1b[37m▁\x1b[0m\x1b[32m█\x1b[0m\x1b[37m▁\x1b[0m", "", "\x1b[32m█\x1b[0m\x1b[37m▁\x1b[0m\x1b[32m█\x1b[0m"]
    assert exp == res, (exp, res)
Esempio n. 26
0
def test_rounding0():
    "Test two values, min and max."

    res = sparklines([1, 5, 8])
    exp = ['▁▅█'] # 1, 5, 8
    assert res == exp
Esempio n. 27
0
def test_pi():
    "Test first eight digits of Pi."

    res = sparklines([3, 1, 4, 1, 5, 9, 2, 6])
    exp = ['▃▁▄▁▄█▂▅']
    assert res == exp
Esempio n. 28
0
def test_maximum():
    res = sparklines([1, 2, 3, 10, 10], maximum=3)
    exp = ['▁▄███']
    assert res == exp
Esempio n. 29
0
def WSsummary(site, screen_plot):
    '''
    Produce a summary of the recent data from a AIMS weather station
    :param site: site ID
    :return: nothing
    '''
    try:
        AIMSurl = "https://api.aims.gov.au/weather/station/" + str(site)
        WSjson = json.loads(requests.get(AIMSurl).text)
        print("Station ID: {id}".format(id=WSjson['site_id']))
        print("Station Name: {stName}".format(stName=WSjson['site_name']))
        print("Station location: {lon}LON, {lat}LAT".format(lon=WSjson['longitude'], lat=WSjson['latitude']))
        print("Station metadata record: {metadata}".format(metadata=WSjson['metadata']))
        if WSjson['status']['online'] == 'true':
            WSstatus = 'ONLINE'
        else:
            WSstatus = 'OFFLINE'
        WSstatusMessage = WSjson['status']['message']
        print("Current Status: {status}: {statusText}".format(status=WSstatus, statusText=WSstatusMessage))
        parameterList = list(WSjson['series'].keys())
        tbl = prettytable.PrettyTable()
        for param in parameterList:
            paramName = WSjson['series'][param]['parameterName']
            minutesAgo = WSjson['series'][param]['minutesAgo']
            paramUnits = WSjson['series'][param]['uomSymbol']
            if len(WSjson['series'][param]['data12Hours']) > 0:
                WSdata = WSjson['series'][param]['data12Hours']
                plotType = 'last 12 Hourly values'
            elif len(WSjson['series'][param]['data7Days']) > 0:
                WSdata = WSjson['series'][param]['data7Days']
                plotType = 'Daily averages'
            else:
                print("NO DATA AVAILABLE")
                return
            WSdate = []
            WSvalue = []
            for item in WSdata:
                WSdate.append(item['date'])
                WSvalue.append(item['qc'])
            paramLastDate = WSdate[-1]
            paramLastValue = WSvalue[-1]
            if screen_plot:
                paramPlot = []
                for v in sparklines(WSvalue):
                    paramPlot.append(v)
                paramPlot = paramPlot[0]
                #if plotType=="Daily averages":
                paramPlot = paramPlot[len(paramPlot)-25:]
                tbl.add_row([paramName, paramUnits, minutesAgo, paramLastDate, paramLastValue, paramPlot])
            else:
                paramPlot = ""
                tbl.add_row([paramName, paramUnits, minutesAgo, paramLastDate, paramLastValue])

        if screen_plot:
            tbl.field_names = ['Parameter', 'Units', 'Last Read (min ago)', 'Last Date', 'Last Value', 'Plot ' + plotType]
        else:
            tbl.field_names = ['Parameter', 'Units', 'Last Read (min ago)', 'Last Date', 'Last Value']

        print(tbl)
    except Exception as e:
        print('ERROR: site ID not found')
    return
Esempio n. 30
0
def test_maximum_internal_consistency():
    res = sparklines([1, 2, 3, 10, 10, 1], maximum=3)
    exp = sparklines([1, 2, 3, 3, 3, 1], maximum=3)
    assert res == exp