Ejemplo n.º 1
0
def plot_attAUC(GT, attributepattern, clf):
    AUC = []
    P = np.loadtxt(attributepattern)
    attributes = get_attributes()

    # Loading ground truth
    test_index = bzUnpickle('./CreatedData/test_features_index.txt')
    test_attributes = get_class_attributes('./Classes/', name='test')
    _, y_true = create_data('./CreatedData/test_featuresVGG19.pic.bz2',
                            test_index, test_attributes)

    for i in range(y_true.shape[1]):
        fp, tp, _ = roc_curve(y_true[:, i], P[:, i])
        roc_auc = auc(fp, tp)
        AUC.append(roc_auc)
    print("Mean attrAUC %g" % (np.nanmean(AUC)))

    xs = np.arange(y_true.shape[1])
    width = 0.5

    fig = plt.figure(figsize=(15, 5))
    ax = fig.add_subplot(1, 1, 1)
    rects = ax.bar(xs, AUC, width, align='center')
    ax.set_xticks(xs)
    ax.set_xticklabels(attributes, rotation=90)
    ax.set_ylabel("area under ROC curve")
    autolabel(rects, ax)
    plt.savefig('results/AwA-AttAUC-DAP-%s.pdf' % clf)
Ejemplo n.º 2
0
 def get_json_object(self, request):
     if not hasattr(self, "objects"):
         attrs = utils.get_model_fields(self)
         attrs.extend(self.json_extra)
         self.objects = utils.get_attributes(
             self,
             attrs,
             self.json_filters,
             processors=[utils.datetime_processor, utils.many_related_processor],
             request=request,
         )
     return self.objects
Ejemplo n.º 3
0
    def get_features(self, image_patches: List[np.ndarray]) -> str:
        ''' Extract the attributes associated to each detection
        :param image_patches: List[np.ndarray] of detections
        :return features: List[np.ndarray] of features associated to each detection
        '''

        features = list()

        for patch in image_patches:
            if patch is not None:
                initial_time = time.time()

                # Transform the np.array into a tensor
                patch_tensor = load_image(patch=patch,
                                          gpu=self.gpu,
                                          patch_size=self.resize_dimensions,
                                          norm_mean=self.mean,
                                          norm_std=self.std)

                # Translating to np.ndarray avoids further issues with deepcopying torch.Tensors (in "tracker")
                # Get the values from the net
                scores = self.model(patch_tensor).data.cpu().numpy().flatten()
                # Translate the net values into a meaningful representation
                attributes = get_attributes(scores=scores)
                final_time = time.time()
                # Console print for debugging
                #print(attributes)
                print(
                    f"[PERFORMANCE] Attributes extracted: {1/(final_time-initial_time)} Hz"
                )
                features.append(attributes.__str__())
            else:
                features.append(None)
                # print("[INFO] None appended")

        return features
Ejemplo n.º 4
0
def serve_layout():
    attributes = get_attributes()

    return html.Div(
        [
            # page title
            html.Title(["Euronext Technology Companies"]),
            # page header
            html.Div([html.H1("Technological Companies Stocks Dashboard")]),
            # summary
            html.Div([
                html.H2("Summary", className="summary-title"),
                html.P(summary_1, className="summary-text"),
                html.P(summary_2, className="summary-text"),
                html.A(
                    "Please visit my GitHub!",
                    href="https://github.com/jschnab/finance-scraping.git",
                    className="summary-text",
                ),
            ],
                     className="summary"),
            # timeseries
            html.Div([html.H2("Timeseries Analysis")]),
            # dropdown grid
            html.Div(
                [
                    # select y axis dropdown
                    html.Div(
                        [
                            html.Div("Select y-axis", className="label"),
                            html.Div(
                                dcc.Dropdown(
                                    id="y_var",
                                    options=attributes,
                                    value="last_quote",
                                    className="dropdown",
                                )),
                        ],
                        className="subcontainer-dropdown",
                    ),
                    # select companies dropdown
                    html.Div(
                        [
                            html.Div("Select companies", className="label"),
                            html.Div(
                                dcc.Dropdown(
                                    id="companies",
                                    options=get_companies(),
                                    value=[
                                        "Capgemini SE",
                                        "Ubisoft Entertainment",
                                        "Dassault Systemes SE",
                                    ],
                                    multi=True,
                                    className="dropdown",
                                )),
                        ],
                        className="subcontainer-dropdown",
                    ),
                    # date picker
                    html.Div(
                        [
                            html.Div("Select date range", className="label"),
                            html.Div(
                                dcc.DatePickerRange(
                                    id="date_range",
                                    min_date_allowed=get_min_date(),
                                    max_date_allowed=get_max_date(),
                                    className="datepicker",
                                )),
                        ],
                        className="subcontainer-dropdown",
                    ),
                ],
                className="container-dropdown",
            ),
            # graph grid
            html.Div(
                [html.Div([dcc.Graph(id="timeseries")])],
                className="timeseries-container",
            ),
            html.Div(html.H2("Company rankings")),
            # tables container
            html.Div(
                [
                    # single table
                    html.Div(
                        [
                            html.H3("Top 10 values", className="top-values"),
                            # table top 10 values dropdown
                            html.Div([
                                html.Div("Table attribute", className="label"),
                                html.Div(
                                    dcc.Dropdown(
                                        id="drop-top-values",
                                        options=attributes,
                                        value="capital",
                                        className="dropdown",
                                    )),
                            ]),
                            # table top 10 values
                            html.Table(id="top-ten-values"),
                        ],
                        className="container-one-table",
                    ),
                    # single table
                    html.Div(
                        [
                            html.H3("Bottom 10 values",
                                    className="top-values"),
                            # table bottom 10 values dropdown
                            html.Div([
                                html.Div("Table attribute", className="label"),
                                html.Div(
                                    dcc.Dropdown(
                                        id="drop-bottom-values",
                                        options=attributes,
                                        value="capital",
                                        className="dropdown",
                                    )),
                            ]),
                            # table bottom 10 values
                            html.Table(id="bottom-ten-values"),
                        ],
                        className="container-one-table",
                    ),
                    # single table
                    html.Div(
                        [
                            html.H3("Top 10 movers", className="top-values"),
                            # table top 10 progressions dropdown
                            html.Div([
                                html.Div("Table attribute", className="label"),
                                html.Div(
                                    dcc.Dropdown(
                                        id="drop-top-prog",
                                        options=attributes,
                                        value="capital",
                                        className="dropdown",
                                    )),
                            ]),
                            # table top 10 progressions
                            html.Table(id="top-ten-prog"),
                        ],
                        className="container-one-table",
                    ),
                    # single table
                    html.Div(
                        [
                            html.H3("Bottom 10 movers",
                                    className="top-values"),
                            # table top 10 progressions dropdown
                            html.Div([
                                html.Div("Table attribute", className="label"),
                                html.Div(
                                    dcc.Dropdown(
                                        id="drop-bottom-prog",
                                        options=attributes,
                                        value="capital",
                                        className="dropdown",
                                    )),
                            ]),
                            # table bottom 10 progressions
                            html.Table(id="bottom-ten-prog"),
                        ],
                        className="container-one-table",
                    )
                ],
                className="container-tables",
            ),
        ],
        className="main",
    )
Ejemplo n.º 5
0
def main(args):
    path_to_config = pathlib.Path(args.path)
    with open(path_to_config) as f:
        config = yaml.load(f)

    path_to_input = pathlib.Path(config['path_to_input'])
    path_to_bb = pathlib.Path(config['path_to_bb'])
    path_to_output = pathlib.Path(config['path_to_output'])
    is_mask_available = config['is_mask_available']

    bb = pd.read_csv(path_to_bb)
    patients = list(bb.PatientID)
    print(f"Total number of patients: {len(patients)}")

    print(f"Resampled images will be saved in {path_to_output}")
    if not os.path.exists(path_to_output):
        os.makedirs(path_to_output, exist_ok=True)

    for p in tqdm(patients):
        # Read images:
        img_ct = read_nifti(path_to_input / p / (p + '_ct.nii.gz'))
        img_pt = read_nifti(path_to_input / p / (p + '_pt.nii.gz'))
        if is_mask_available:
            mask = read_nifti(path_to_input / p / (p + '_ct_gtvt.nii.gz'))

        # Get bounding boxes:
        pt1 = bb.loc[bb.PatientID == p, ['x1', 'y1', 'z1']]
        pt2 = bb.loc[bb.PatientID == p, ['x2', 'y2', 'z2']]
        pt1, pt2 = tuple(*pt1.values), tuple(*pt2.values)

        # Convert physcial points into array indexes:
        pt1_ct = img_ct.TransformPhysicalPointToIndex(pt1)
        pt1_pt = img_pt.TransformPhysicalPointToIndex(pt1)
        if is_mask_available:
            pt1_mask = mask.TransformPhysicalPointToIndex(pt1)

        pt2_ct = img_ct.TransformPhysicalPointToIndex(pt2)
        pt2_pt = img_pt.TransformPhysicalPointToIndex(pt2)
        if is_mask_available:
            pt2_mask = mask.TransformPhysicalPointToIndex(pt2)

        # Exctract the patch:
        cr_img_ct = img_ct[pt1_ct[0]:pt2_ct[0], pt1_ct[1]:pt2_ct[1],
                           pt1_ct[2]:pt2_ct[2]]
        cr_img_pt = img_pt[pt1_pt[0]:pt2_pt[0], pt1_pt[1]:pt2_pt[1],
                           pt1_pt[2]:pt2_pt[2]]
        if is_mask_available:
            cr_mask = mask[pt1_mask[0]:pt2_mask[0], pt1_mask[1]:pt2_mask[1],
                           pt1_mask[2]:pt2_mask[2]]

        # Resample all images using CT attributes:
        # CT:
        cr_img_ct = resample_sitk_image(cr_img_ct,
                                        new_spacing=[1, 1, 1],
                                        new_size=[144, 144, 144],
                                        interpolator=sitk.sitkLinear)
        target_size = list(cr_img_ct.GetSize())
        attributes = get_attributes(cr_img_ct)

        # PT:
        cr_img_pt = resample_sitk_image(cr_img_pt,
                                        new_spacing=[1, 1, 1],
                                        new_size=target_size,
                                        attributes=attributes,
                                        interpolator=sitk.sitkLinear)

        # Mask:
        if is_mask_available:
            cr_mask = resample_sitk_image(
                cr_mask,
                new_spacing=[1, 1, 1],
                new_size=target_size,
                attributes=attributes,
                interpolator=sitk.sitkNearestNeighbor)

        # Save resampled images:
        if not os.path.exists(path_to_output / p):
            os.makedirs(path_to_output / p, exist_ok=True)

        write_nifti(cr_img_ct, path_to_output / p / (p + '_ct.nii.gz'))
        write_nifti(cr_img_pt, path_to_output / p / (p + '_pt.nii.gz'))
        if is_mask_available:
            write_nifti(cr_mask, path_to_output / p / (p + '_ct_gtvt.nii.gz'))