Exemplo n.º 1
0
    def open_file_name_dialog(self):
        fileName, _ = QFileDialog.getOpenFileName(self, caption="Choose shape to view.", filter="All Files (*);; Model Files (.obj, .off, .ply, .stl)")
        if not (fileName or self.check_file(fileName)):
            return False

        mesh = DataSet._read(fileName)
        return mesh
Exemplo n.º 2
0
 def dropEvent(self, e):
     if len(e.mimeData().urls()) == 1:
         file = QUrl.toLocalFile(e.mimeData().urls()[0])
         self.load_and_prep_query_mesh(DataSet._read(file))
     else:
         error_dialog = QtWidgets.QErrorMessage(parent=self)
         error_dialog.showMessage("Please drag only one mesh at the time.")
Exemplo n.º 3
0
 def open_file_name_dialog(self):
     fileName, _ = QFileDialog.getOpenFileName(
         self,
         caption="Choose shape to view.",
         filter="All Files (*);; Model Files (.obj, .off, .ply, .stl)")
     if fileName:
         mesh = DataSet._read(fileName)
         return mesh
     return None
Exemplo n.º 4
0
 def __init__(self, feature_data_file=FEATURE_DATA_FILE, label_coarse=False):
     self.label_coarse = label_coarse
     self.reader = DataSet("")
     self.query_matcher = QueryMatcher(feature_data_file, label_coarse=label_coarse)
     self.feature_db_flattened = self.query_matcher.features_flattened
     self.feature_db_raw = self.query_matcher.features_raw
     self.features_df_flat = pd.DataFrame(self.feature_db_flattened).set_index('name')
     self.features_df_raw = pd.DataFrame(self.feature_db_raw).set_index('name')
     self.mesh_classes_count = self.features_df_flat['label'].value_counts()
     if self.label_coarse:
         self.mesh_classes_count = self.features_df_flat['label_coarse'].value_counts().rename("label")
Exemplo n.º 5
0
 def plot_selected_mesh(self):
     mesh_name = self.list.selectedItems()[0].toolTip()
     path_to_mesh = glob.glob(self.config_data["DATA_PATH_NORMED"] + "\\**\\" + mesh_name + ".*", recursive=True)
     data = DataSet._load_ply(path_to_mesh[0])
     mesh = pv.PolyData(data["vertices"], data["faces"])
     mesh_features = [d for d in self.query_matcher.features_raw_init if d["name"] == mesh_name][0]
     if len(self.smw_list) != 0:
         self.smw_list[0].deleteLater()
         self.smw_list.remove(self.smw_list[0])
     self.smw = SimilarMeshWindow(mesh, mesh_features)
     self.smw_list.append(self.smw)
     self.smw.show()
Exemplo n.º 6
0
def train():
    tr_config = {
        'flag': True,
        'rg': 25,  # 7, 5
        'wrg': 0.25,  # 1, 3
        'hrg': 0.25,  # 1, 3
        'zoom': 0.25  # 1, 1
    }
    callbacks = get_callbacks('mynet_v4_bias', patience=30)

    paths, y = search_file('set1/segmented_set1')
    paths, y = search_file('set2/segmented_set2', paths=paths, y=y)

    ds = DataSet(nframe=30,
                 fstride=6,
                 name='UT interaction',
                 size=[224, 224, 3],
                 filepaths=paths,
                 y=y,
                 kernel_size=4)
    ds.make_set(op='msqr', name='train')
    ds.make_set(op='msqr', name='valid')

    #opt = Adam(lr=1e-4, beta_1=0.9, beta_2=0.999, decay=0.1)
    #opt = SGD(lr=2*1e-1, momentum=0.9, nesterov=True, decay=0.2)
    opt = RMSprop(lr=0.001, rho=0.9, decay=0.01)

    model = MobileNet(alpha=1.0, shape=[29, 56, 56, 1], nframe=29)
    model.compile(optimizer=opt,
                  loss='categorical_crossentropy',
                  metrics=['accuracy'])
    model.summary()

    #model.load_weights('mynet_v4.h5')
    model.fit_generator(generator=ds.train_gen(batch_size=5,
                                               aug_config=tr_config),
                        steps_per_epoch=100,
                        epochs=300,
                        validation_data=ds.valid_gen(),
                        verbose=1,
                        validation_steps=ds.getVlen,
                        callbacks=callbacks)
Exemplo n.º 7
0
import pandas as pd
import scipy

if __name__ == "__main__":
    origFaceareas = []
    normedFaceareas = []

    origDB = PSBDataset(DATA_PATH_PSB, class_file_path=CLASS_FILE)
    origDB.read()
    origDB.load_files_in_memory()

    normedDB = PSBDataset(DATA_PATH_NORMED, class_file_path=CLASS_FILE)
    normedDB.read()
    normedDB.load_files_in_memory()

    origFaceareas = [DataSet.get_only_cell_areas(mesh.get('data').get('vertices'), mesh.get('data').get('faces')) for mesh in origDB.full_data]
    origFaceareas = list(itertools.chain(*origFaceareas))
    origFaceareas_sub = pd.DataFrame(origFaceareas, columns=['fa'])
    origFaceareas_sub.to_csv("bitstats_origFaceAreas.csv")
    normedFaceareas = [DataSet.get_only_cell_areas(mesh.get('data').get('vertices'), mesh.get('data').get('faces')) for mesh in normedDB.full_data]
    normedFaceareas = list(itertools.chain(*normedFaceareas))
    normedFaceareas = pd.DataFrame(normedFaceareas, columns=['fa'])    
    normedFaceareas.to_csv("bitstats_normedFaceAreas.csv")

    # origFaceareas_sub = origFaceareas_sub.sort_values(by='fa')
    # origFaceareas_sub = origFaceareas_sub[origFaceareas_sub['fa'] > 0]
    # origFaceareas_sub = origFaceareas_sub.iloc[int(.5 * len(origFaceareas_sub)):int(.80 * len(origFaceareas_sub))]
    # origFaceareas_sub['fa'] = origFaceareas_sub['fa'] * 10000
    # origmin = min(origFaceareas_sub['fa'])
    # origmax = max(origFaceareas_sub['fa'])
# %%
from feature_extractor import FeatureExtractor
from normalizer import Normalizer
from reader import PSBDataset, DataSet
from helper.config import FEATURE_DATA_FILE, DEBUG, DATA_PATH_NORMED_SUBSET, DATA_PATH_NORMED, CLASS_FILE, DATA_PATH_PSB, DATA_PATH_DEBUG
import time
import pyvista as pv
from pprint import pprint

# %%
if __name__ == "__main__":

    print("=" * 10 + "Testing full pipeline for mono pipeline" + "=" * 10)
    descriptor = DataSet._extract_descr("ant.off")
    data_item = DataSet.mono_run_pipeline(descriptor)
    normed_data_item = Normalizer.mono_run_pipeline(data_item)
    features_data_item = FeatureExtractor.mono_run_pipeline(normed_data_item)

    pprint(features_data_item)

    plotter = pv.Plotter(shape=(1, 2))
    plotter.subplot(0, 0)
    plotter.add_text("Unnormalized", font_size=30)
    plotter.add_mesh(pv.PolyData(data_item["data"]["vertices"],
                                 data_item["data"]["faces"]),
                     show_edges=True)
    plotter.show_bounds(all_edges=True)
    plotter.subplot(0, 1)
    plotter.add_text("Normalized", font_size=30)
    plotter.add_mesh(pv.PolyData(normed_data_item["data"]["vertices"],
                                 normed_data_item["data"]["faces"]),
Exemplo n.º 9
0
def plot_mesh(mesh, ax):
    points = mesh.points
    X, Y, Z = points[:, 0], points[:, 1], points[:, 2]
    faces = DataSet._get_cells(mesh)
    return ax.plot_trisurf(X, Y, Z=Z, triangles=faces)
Exemplo n.º 10
0
def plot_comparison(sample_labels, distance):
    qm = QueryMatcher(FEATURE_DATA_FILE)
    labelled_occurences = tuple(
        zip(sample_labels, [
            Counter(pd.DataFrame(qm.features_flattened)["label"]).get(lbl)
            for lbl in sample_labels
        ]))
    names = [[f for f in qm.features_raw if f["label"] == lbl][0]["name"]
             for lbl in sample_labels]
    sampled_labelled = dict(zip(labelled_occurences, names))
    paths = []

    for path, subdirs, files in os.walk(DATA_PATH_PSB):
        for name in files:
            if ("off" or "ply") in name:
                paths.append(os.path.join(path, name))

    n_singletons, n_distributionals, mapping_of_labels = get_sizes_features(
        with_labels=True)

    n_hist = len(
        [key for key, val in mapping_of_labels.items() if "hist_" in key])
    n_skeleton = len(
        [key for key, val in mapping_of_labels.items() if "skeleton_" in key])

    if distance != "knn":
        # Custom
        weights = ([3]) + \
                  ([100] * n_hist) + \
                  ([1] * n_skeleton)

        function_pipeline = [cosine] + \
                            ([wasserstein_distance] * n_hist) + \
                            ([wasserstein_distance] * n_skeleton)
    else:
        # KNN
        weights = ([1]) + \
                  ([1] * n_hist) + \
                  ([1] * n_skeleton)

        function_pipeline = [QueryMatcher.perform_knn] + (
            [QueryMatcher.perform_knn] * n_distributionals)

    normalizer = Normalizer()
    out_dict = defaultdict(list)
    for info_tuple, mesh_idx in sampled_labelled.items():
        full_path = [p for p in paths if mesh_idx in p][0]
        print(f"Processing: {full_path}")
        mesh = DataSet._read(Path(full_path))
        normed_data = normalizer.mono_run_pipeline(mesh)
        normed_mesh = pv.PolyData(
            normed_data["history"][-1]["data"]["vertices"],
            normed_data["history"][-1]["data"]["faces"])
        normed_data['poly_data'] = normed_mesh

        features_dict = FeatureExtractor.mono_run_pipeline_old(normed_data)

        indices, distance_values, _ = qm.match_with_db(
            features_dict,
            k=10,
            distance_functions=function_pipeline,
            weights=weights)
        if mesh_idx in indices:
            idx_of_idx = indices.index(mesh_idx)
            indices.remove(mesh_idx)
            del distance_values[idx_of_idx]
            distance_values.insert(0, 0)

        indices = indices[4:]
        indices.insert(0, mesh_idx)
        distance_values = distance_values[5:]
        out_dict[info_tuple].append({mesh_idx: (indices, distance_values)})
        print(out_dict)

    class_idx = 0
    plt = pv.Plotter(off_screen=True, shape=(6, 5))
    for key, val in out_dict.items():
        print(class_idx)
        for v in val:
            el_idx = 0
            distances = list(list(v.values())[0][1])
            for name, dist in zip(list(v.values())[0][0], distances):
                print(el_idx)
                plt.subplot(class_idx, el_idx)

                full_path = [p for p in paths if name in p][0]

                mesh = DataSet._read(Path(full_path))
                curr_mesh = pv.PolyData(mesh["data"]["vertices"],
                                        mesh["data"]["faces"])
                plt.add_mesh(curr_mesh, color='r')
                plt.reset_camera()
                plt.view_isometric()
                if el_idx != 0:
                    plt.add_text(f"{el_idx} - Dist: {round(dist,4)}",
                                 font_size=20)
                elif el_idx == 0 and class_idx == 0:
                    plt.add_text(
                        f"             Query\nClass: {key[0].replace('_', ' ').title()}"
                        + f"\nInstances: {key[1]}",
                        font_size=20)
                else:
                    plt.add_text(f"Class: {key[0].replace('_', ' ').title()}" +
                                 f"\nInstances: {key[1]}",
                                 font_size=20)

                el_idx += 1
        class_idx += 1

    if distance == "knn":
        plt.screenshot(f"fig\\comparison_knn.jpg", window_size=(1920, 2160))
    else:
        plt.screenshot(f"figs\\comparison_custom_distance.jpg",
                       window_size=(1920, 2160))