()
| 17 | random.seed(5) |
| 18 | |
| 19 | def run(): |
| 20 | |
| 21 | #argparse |
| 22 | parser = argparse.ArgumentParser(description='Get the weights of each dimensions after training a strand VAE') |
| 23 | parser.add_argument('--strand_checkpoint_path', default="./checkpoints/strand_vae/strand_codec.pt", type=str, help='Path to the strandVAE checkpoint') |
| 24 | parser.add_argument('--difflocks_checkpoint_path', default="./checkpoints/difflocks_diffusion/scalp_v9_40k_06730000.pth", type=str, help='Path to the difflocks checkpoint') |
| 25 | parser.add_argument('--difflocks_config_path', default="./configs/config_scalp_texture_conditional.json", type=str, help='Path to the difflocks config') |
| 26 | parser.add_argument('--rgb2mat_checkpoint_path', default="./checkpoints/rgb2material/rgb2material.pt", type=str, help='Path to the rgb2material checkpoint') |
| 27 | parser.add_argument('--blender_path', type=str, default="", help='Path to the blender executable') |
| 28 | parser.add_argument('--blender_nr_threads', default=8, type=int, help='Number of threads for blender to use') |
| 29 | parser.add_argument('--blender_strands_subsample', default=1.0, type=float, help='Amount of subsample of the strands(1.0=full strands, 0.5=half strands)') |
| 30 | parser.add_argument('--blender_vertex_subsample', default=1.0, type=float, help='Amount of subsample of the vertices(1.0=all vertex, 0.5=half number of vertices per strand)') |
| 31 | parser.add_argument('--alembic_resolution', default=7, type=int, help='Resolution of the exported alembic') |
| 32 | parser.add_argument('--export_alembic', action='store_true', help='weather to export alembic or not') |
| 33 | parser.add_argument('--do_shrinkwrap', action='store_true', help='applies a shrinkwrap modifier in blender that pushes the strands away from the scalp so they dont pass through the head') |
| 34 | parser.add_argument('--img_path', type=str, required=True, help='Path to the image to do inference on') |
| 35 | parser.add_argument('--out_path', type=str, required=True, help='Path to the image to do inference on') |
| 36 | args = parser.parse_args() |
| 37 | |
| 38 | print("args is", args) |
| 39 | |
| 40 | difflocks= DiffLocksInference(args.strand_checkpoint_path, args.difflocks_config_path, args.difflocks_checkpoint_path, args.rgb2mat_checkpoint_path) |
| 41 | |
| 42 | |
| 43 | #run---- |
| 44 | # img_path="./samples/medium_11.png" |
| 45 | strand_points_world, hair_material_dict=difflocks.file2hair(args.img_path, args.out_path) |
| 46 | print("hair_material_dict",hair_material_dict) |
| 47 | |
| 48 | |
| 49 | #create blender file and optionally an alembic file |
| 50 | if args.blender_path!="": |
| 51 | cmd=[args.blender_path, "-t", str(args.blender_nr_threads), "--background", "--python", "./inference/npz2blender.py", "--", "--input_npz", os.path.join(args.out_path,"difflocks_output_strands.npz"), "--out_path", args.out_path, "--strands_subsample", str(args.blender_strands_subsample), "--vertex_subsample", str(args.blender_vertex_subsample), "--alembic_resolution", str(args.alembic_resolution) ] |
| 52 | if args.do_shrinkwrap: |
| 53 | cmd.append("--shrinkwrap") |
| 54 | if args.export_alembic: |
| 55 | cmd.append("--export_alembic") |
| 56 | subprocess.run(cmd, capture_output=False) |
| 57 | |
| 58 | print("Finished writing to ", args.out_path) |
| 59 | |
| 60 | if __name__ == '__main__': |
| 61 |
no test coverage detected