Exemple #1
0
    def create_library(self) -> ModelLibrarian:
        lib = self._get_librarian("ShapeNetSEM")
        first_time_only = True
        metadata_path = self.src.joinpath("metadata.csv")
        with open(str(metadata_path), newline='') as csvfile:
            reader = csv.reader(csvfile)
            for row in reader:
                if first_time_only:
                    first_time_only = False
                    continue
                if row[1] == "" or row[3] == "":
                    continue
                record = ModelRecord()
                record.name = row[0][4:]
                record.wcategory = row[3].split(",")[0]
                record.wnid = f"n{int(row[2][1:]):08d}"

                for platform in record.urls:
                    record.urls[platform] = self._get_url(
                        record.wnid, record.name, platform)
                lib.add_or_update_record(record, overwrite=False, write=False)
        # Write to disk.
        lib.write(pretty=False)

        # Move the textures.
        any_textures = False
        for f in self.src.joinpath("textures").rglob("*.jpg"):
            f.replace(self.src.joinpath(f"models/{f.name}"))
            any_textures = True
        if any_textures:
            print("Moved all .jpg files in textures/ to models/")
        return lib
Exemple #2
0
    def create_library(self) -> ModelLibrarian:
        # Load the taxonomy file.
        metadata = json.loads(
            self._get_metadata_path().read_text(encoding="utf-8"))
        # Create a new library.
        lib = self._get_librarian("ShapeNetCoreVal")

        # Process each .obj file.
        for f in self.src.rglob("*.obj"):
            record = ModelRecord()
            record.name = f.parts[-3]
            record.wnid = metadata[record.name]['wnid']
            record.wcategory = metadata[record.name]['wcategory']
            for platform in record.urls:
                record.urls[platform] = self._get_url(record.wnid, record.name,
                                                      platform)

            lib.add_or_update_record(record, overwrite=False, write=False)

        # Write to disk. Don't pretty-print (saves about 60 MB).
        lib.write(pretty=False)
        return lib
Exemple #3
0
    def create_library(self) -> ModelLibrarian:
        # Load the taxonomy file.
        taxonomy_raw = json.loads(self._get_taxonomy_path().read_text(encoding="utf-8"))
        taxonomy = dict()
        for synset in taxonomy_raw:
            taxonomy.update({synset["synsetId"]: synset["name"].split(",")[0]})
        # Create a new library.
        lib = self._get_librarian("ShapeNetCore")

        # Process each .obj file.
        for f in self.src.rglob("*.obj"):
            wnid = f.parts[-4]
            record = ModelRecord()
            record.name = f.parts[-3]
            record.wnid = "n" + wnid
            record.wcategory = taxonomy[wnid]
            for platform in record.urls:
                record.urls[platform] = self._get_url(record.wnid, record.name, platform)

            lib.add_or_update_record(record, overwrite=False, write=False)

        # Write to disk. Don't pretty-print (saves about 60 MB).
        lib.write(pretty=False)
        return lib