File size: 3,660 Bytes
66388d5
 
1b6648d
 
 
 
 
 
 
 
 
 
 
 
66388d5
1b6648d
 
 
c42dae7
 
 
1b6648d
e6cb6f8
1b6648d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dc9b09f
1b6648d
dc9b09f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
---
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](https://huggingface.co/datasets/tfnn/thispersondoesnotexist_to_triposr_6748_3D_Heads) dataset as a foundation.

The heads dataset was collecting using the scraper [Dataset_Scraper.7z](https://huggingface.co/datasets/tfnn/HeadsNet/resolve/main/Dataset_Scraper.7z?download=true) based on [TripoSR](https://github.com/VAST-AI-Research/TripoSR) with [this marching cubes improvement](https://github.com/VAST-AI-Research/TripoSR/issues/22#issuecomment-2010318709) by [thatname/zephyr](https://github.com/thatname) which converts the 2D images from [ThisPersonDoesNotExist](https://thispersondoesnotexist.com/) 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](https://www.blender.org/) script:
```
import bpy
import glob
import pathlib
if not isdir(outputDir): mkdir(outputDir)
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](https://huggingface.co/datasets/tfnn/HeadsNet/resolve/main/DatasetGen_2_6.7z?download=true) using [RPLY](https://w3.impa.br/~diego/software/rply/) to load the PLY files and convert them to binary data which I have provided here [HeadsNet-2-6.7z](https://huggingface.co/datasets/tfnn/HeadsNet/resolve/main/HeadsNet-2-6.7z?download=true).

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](https://huggingface.co/datasets/tfnn/HeadsNet/resolve/main/nan_check.py?download=true).

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)
```