HeadsNet / README.md
tfnn's picture
Update README.md
6f26544 verified
|
raw
history blame
5.07 kB
metadata
license: mit
tags:
  - thispersondoesnotexist
  - stylegan
  - stylegan2
  - mesh
  - model
  - 3d
  - asset
  - generative
pretty_name: HeadsNet
size_categories:
  - 1K<n<10K

HeadsNet

This dataset uses the thispersondoesnotexist_to_triposr_6748_3D_Heads dataset as a foundation.

The heads dataset was collecting using the scraper Dataset_Scraper.7z based on TripoSR with this marching cubes improvement by thatname/zephyr which converts the 2D images from ThisPersonDoesNotExist to 3D meshes.

Vertex Normals need to be generated before we can work with this dataset, the easiest method to achieve this was with a simple Blender script:

import bpy
import glob
import pathlib
from os import mkdir
from os.path import isdir
importDir = "ply/"
outputDir = "ply_norm/"
if not isdir(outputDir): mkdir(outputDir)

for file in glob.glob(importDir + "*.ply"):
    model_name = pathlib.Path(file).stem
    if pathlib.Path(outputDir+model_name+'.ply').is_file() == True: continue
    bpy.ops.wm.ply_import(filepath=file)
    bpy.ops.wm.ply_export(
                            filepath=outputDir+model_name+'.ply',
                            filter_glob='*.ply',
                            check_existing=False,
                            ascii_format=False,
                            export_selected_objects=False,
                            apply_modifiers=True,
                            export_triangulated_mesh=True,
                            export_normals=True,
                            export_uv=False,
                            export_colors='SRGB',
                            global_scale=1.0,
                            forward_axis='Y',
                            up_axis='Z'
                        )
    bpy.ops.object.select_all(action='SELECT')
    bpy.ops.object.delete(use_global=False)
    bpy.ops.outliner.orphans_purge()
    bpy.ops.outliner.orphans_purge()
    bpy.ops.outliner.orphans_purge()

Importing the PLY without normals causes Blender to automatically generate them.

At this point the PLY files now need to be converted to training data, for this I wrote a C program DatasetGen_2_6.7z using RPLY to load the PLY files and convert them to binary data which I have provided here HeadsNet-2-6.7z.

It's always good to NaN check your training data after generating it so I have provided a simple Python script for that here nan_check.py.

This binary training data can be loaded into Python using:

load_x = []
  with open("train_x.dat", 'rb') as f:
    load_x = np.fromfile(f, dtype=np.float32)

load_y = []
  with open("train_y.dat", 'rb') as f:
    load_y = np.fromfile(f, dtype=np.float32)

The data can then be reshaped and saved back out as a numpy array which makes for faster loading:

inputsize = 2
outputsize = 6
train_x = np.reshape(load_x, [tss, inputsize])
train_y = np.reshape(load_y, [tss, outputsize])
np.save("train_x.npy", train_x)
np.save("train_y.npy", train_y)

The basic premise of how this network is trained and thus how the dataset is generated in the C program is:

  1. All models are scaled to a normal cubic scale and then scaled again by 0.55 so that they all fit within a unit sphere.
  2. All model vertices are reverse traced from the vertex position to the perimeter of the unit sphere using the vertex normal.
  3. The nearest position on a 10,242 vertex icosphere is found and the network is trained to output the model vertex position and vertex color (6 components) at the index of the icosphere vertex.
  4. The icosphere vertex index is scaled to a 0-1 range before being input to the network.
  5. The network only has two input parameters, the other parameter is a 0-1 model ID which is randomly selected and all vertices for a specific model are trained into the network using the randomly selected ID.
  6. The ID allows one to use this parameter as a random seed, to generate a random Head using this network you would input a random 0-1 seed and then iterate the icosphere index parameter to some sample range between 0-1 so if you wanted a 20,000 vertex head you would iterate between 0-1 at 20,000 increments of 0.00005 as the network outputs one vertex position and vertex color for each forward-pass.

More about this network topology can be read here: https://gist.github.com/mrbid/1eacdd9d9239b2d324a3fa88591ff852