jadechoghari commited on
Commit
19fb693
1 Parent(s): 2a534b4

update and include model files

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. CODE_OF_CONDUCT.md +80 -0
  2. CONTRIBUTING.md +31 -0
  3. LICENSE +399 -0
  4. README.md +58 -168
  5. __init__.py +1 -0
  6. assets/40_prompt_images/A 3D scan of AK47, weapon.jpeg +0 -0
  7. assets/40_prompt_images/A DSLR photo of Sydney Opera House.jpg +0 -0
  8. assets/40_prompt_images/A bald eagle carved out of wood.jpg +0 -0
  9. assets/40_prompt_images/A bulldog wearing a black pirate hat.jpeg +0 -0
  10. assets/40_prompt_images/A crab, low poly.jpg +0 -0
  11. assets/40_prompt_images/A photo of a horse walking.jpeg +0 -0
  12. assets/40_prompt_images/A pig wearing a backpack.jpeg +0 -0
  13. assets/40_prompt_images/A product photo of a toy tank.jpg +0 -0
  14. assets/40_prompt_images/A see no evil monkey on a kick drum.jpg +0 -0
  15. assets/40_prompt_images/A statue of angel, blender.jpg +0 -0
  16. assets/40_prompt_images/Corgi riding a rocket.jpeg +0 -0
  17. assets/40_prompt_images/Daenerys Targaryen from game of throne.jpg +0 -0
  18. assets/40_prompt_images/Darth Vader helmet,g highly detailed.jpg +0 -0
  19. assets/40_prompt_images/Dragon armor.jpeg +0 -0
  20. assets/40_prompt_images/Fisherman House, cute, cartoon, blender, stylized.jpg +0 -0
  21. assets/40_prompt_images/Flying Dragon, highly detailed, breathing fire.jpeg +0 -0
  22. assets/40_prompt_images/Handpainted watercolor windmill, hand-painted.jpg +0 -0
  23. assets/40_prompt_images/Katana.jpeg +0 -0
  24. assets/40_prompt_images/Little italian town, hand-painted style.jpg +0 -0
  25. assets/40_prompt_images/Mr Bean Cartoon doing a T Pose.jpg +0 -0
  26. assets/40_prompt_images/Pedestal Fan (White).jpeg +0 -0
  27. assets/40_prompt_images/Pikachu with hat.jpg +0 -0
  28. assets/40_prompt_images/Samurai koala bear.jpg +0 -0
  29. assets/40_prompt_images/TRUMP figure.jpg +0 -0
  30. assets/40_prompt_images/Viking axe, fantasy, weapon, blender, 8k, HD.jpg +0 -0
  31. assets/40_prompt_images/a DSLR photo of a frog wearing a sweater.jpg +0 -0
  32. assets/40_prompt_images/a DSLR photo of a ghost eating a hamburger.jpg +0 -0
  33. assets/40_prompt_images/a DSLR photo of a peacock on a surfboard.jpeg +0 -0
  34. assets/40_prompt_images/a DSLR photo of a squirrel playing guitar.jpg +0 -0
  35. assets/40_prompt_images/a DSLR photo of an eggshell broken in two with an adorable chick standing next to it.jpeg +0 -0
  36. assets/40_prompt_images/an astronaut riding a horse.jpeg +0 -0
  37. assets/40_prompt_images/animal skull pile.jpg +0 -0
  38. assets/40_prompt_images/army Jacket, 3D scan.jpg +0 -0
  39. assets/40_prompt_images/baby yoda in the style of Mormookiee.jpg +0 -0
  40. assets/40_prompt_images/beautiful, intricate butterfly.jpg +0 -0
  41. assets/40_prompt_images/girl riding wolf, cute, cartoon, blender.jpg +0 -0
  42. assets/40_prompt_images/mecha vampire girl chibi.jpg +0 -0
  43. assets/40_prompt_images/military Mech, future, scifi.jpg +0 -0
  44. assets/40_prompt_images/motorcycle, scifi, blender.jpeg +0 -0
  45. assets/40_prompt_images/saber from fate stay night, 3D, girl, anime.jpeg +0 -0
  46. install.sh +25 -0
  47. lrm/__init__.py +5 -0
  48. lrm/cam_utils.py +138 -0
  49. lrm/inferrer.py +232 -0
  50. lrm/models/__init__.py +5 -0
CODE_OF_CONDUCT.md ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to make participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, sex characteristics, gender identity and expression,
9
+ level of experience, education, socio-economic status, nationality, personal
10
+ appearance, race, religion, or sexual identity and orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies within all project spaces, and it also applies when
49
+ an individual is representing the project or its community in public spaces.
50
+ Examples of representing a project or community include using an official
51
+ project e-mail address, posting via an official social media account, or acting
52
+ as an appointed representative at an online or offline event. Representation of
53
+ a project may be further defined and clarified by project maintainers.
54
+
55
+ This Code of Conduct also applies outside the project spaces when there is a
56
+ reasonable belief that an individual's behavior may have a negative impact on
57
+ the project or its community.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported by contacting the project team at <[email protected]>. All
63
+ complaints will be reviewed and investigated and will result in a response that
64
+ is deemed necessary and appropriate to the circumstances. The project team is
65
+ obligated to maintain confidentiality with regard to the reporter of an incident.
66
+ Further details of specific enforcement policies may be posted separately.
67
+
68
+ Project maintainers who do not follow or enforce the Code of Conduct in good
69
+ faith may face temporary or permanent repercussions as determined by other
70
+ members of the project's leadership.
71
+
72
+ ## Attribution
73
+
74
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
75
+ available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
76
+
77
+ [homepage]: https://www.contributor-covenant.org
78
+
79
+ For answers to common questions about this code of conduct, see
80
+ https://www.contributor-covenant.org/faq
CONTRIBUTING.md ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Contributing to PoseDiffusion
2
+ We want to make contributing to this project as easy and transparent as
3
+ possible.
4
+
5
+ ## Pull Requests
6
+ We actively welcome your pull requests.
7
+
8
+ 1. Fork the repo and create your branch from `main`.
9
+ 2. If you've added code that should be tested, add tests.
10
+ 3. If you've changed APIs, update the documentation.
11
+ 4. Ensure the test suite passes.
12
+ 5. Make sure your code lints.
13
+ 6. If you haven't already, complete the Contributor License Agreement ("CLA").
14
+
15
+ ## Contributor License Agreement ("CLA")
16
+ In order to accept your pull request, we need you to submit a CLA. You only need
17
+ to do this once to work on any of Facebook's open source projects.
18
+
19
+ Complete your CLA here: <https://code.facebook.com/cla>
20
+
21
+ ## Issues
22
+ We use GitHub issues to track public bugs. Please ensure your description is
23
+ clear and has sufficient instructions to be able to reproduce the issue.
24
+
25
+ Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe
26
+ disclosure of security bugs. In those cases, please go through the process
27
+ outlined on that page and do not file a public issue.
28
+
29
+ ## License
30
+ By contributing to PoseDiffusion, you agree that your contributions will be licensed
31
+ under the LICENSE file in the root directory of this source tree.
LICENSE ADDED
@@ -0,0 +1,399 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Attribution-NonCommercial 4.0 International
2
+
3
+ =======================================================================
4
+
5
+ Creative Commons Corporation ("Creative Commons") is not a law firm and
6
+ does not provide legal services or legal advice. Distribution of
7
+ Creative Commons public licenses does not create a lawyer-client or
8
+ other relationship. Creative Commons makes its licenses and related
9
+ information available on an "as-is" basis. Creative Commons gives no
10
+ warranties regarding its licenses, any material licensed under their
11
+ terms and conditions, or any related information. Creative Commons
12
+ disclaims all liability for damages resulting from their use to the
13
+ fullest extent possible.
14
+
15
+ Using Creative Commons Public Licenses
16
+
17
+ Creative Commons public licenses provide a standard set of terms and
18
+ conditions that creators and other rights holders may use to share
19
+ original works of authorship and other material subject to copyright
20
+ and certain other rights specified in the public license below. The
21
+ following considerations are for informational purposes only, are not
22
+ exhaustive, and do not form part of our licenses.
23
+
24
+ Considerations for licensors: Our public licenses are
25
+ intended for use by those authorized to give the public
26
+ permission to use material in ways otherwise restricted by
27
+ copyright and certain other rights. Our licenses are
28
+ irrevocable. Licensors should read and understand the terms
29
+ and conditions of the license they choose before applying it.
30
+ Licensors should also secure all rights necessary before
31
+ applying our licenses so that the public can reuse the
32
+ material as expected. Licensors should clearly mark any
33
+ material not subject to the license. This includes other CC-
34
+ licensed material, or material used under an exception or
35
+ limitation to copyright. More considerations for licensors:
36
+ wiki.creativecommons.org/Considerations_for_licensors
37
+
38
+ Considerations for the public: By using one of our public
39
+ licenses, a licensor grants the public permission to use the
40
+ licensed material under specified terms and conditions. If
41
+ the licensor's permission is not necessary for any reason--for
42
+ example, because of any applicable exception or limitation to
43
+ copyright--then that use is not regulated by the license. Our
44
+ licenses grant only permissions under copyright and certain
45
+ other rights that a licensor has authority to grant. Use of
46
+ the licensed material may still be restricted for other
47
+ reasons, including because others have copyright or other
48
+ rights in the material. A licensor may make special requests,
49
+ such as asking that all changes be marked or described.
50
+ Although not required by our licenses, you are encouraged to
51
+ respect those requests where reasonable. More_considerations
52
+ for the public:
53
+ wiki.creativecommons.org/Considerations_for_licensees
54
+
55
+ =======================================================================
56
+
57
+ Creative Commons Attribution-NonCommercial 4.0 International Public
58
+ License
59
+
60
+ By exercising the Licensed Rights (defined below), You accept and agree
61
+ to be bound by the terms and conditions of this Creative Commons
62
+ Attribution-NonCommercial 4.0 International Public License ("Public
63
+ License"). To the extent this Public License may be interpreted as a
64
+ contract, You are granted the Licensed Rights in consideration of Your
65
+ acceptance of these terms and conditions, and the Licensor grants You
66
+ such rights in consideration of benefits the Licensor receives from
67
+ making the Licensed Material available under these terms and
68
+ conditions.
69
+
70
+ Section 1 -- Definitions.
71
+
72
+ a. Adapted Material means material subject to Copyright and Similar
73
+ Rights that is derived from or based upon the Licensed Material
74
+ and in which the Licensed Material is translated, altered,
75
+ arranged, transformed, or otherwise modified in a manner requiring
76
+ permission under the Copyright and Similar Rights held by the
77
+ Licensor. For purposes of this Public License, where the Licensed
78
+ Material is a musical work, performance, or sound recording,
79
+ Adapted Material is always produced where the Licensed Material is
80
+ synched in timed relation with a moving image.
81
+
82
+ b. Adapter's License means the license You apply to Your Copyright
83
+ and Similar Rights in Your contributions to Adapted Material in
84
+ accordance with the terms and conditions of this Public License.
85
+
86
+ c. Copyright and Similar Rights means copyright and/or similar rights
87
+ closely related to copyright including, without limitation,
88
+ performance, broadcast, sound recording, and Sui Generis Database
89
+ Rights, without regard to how the rights are labeled or
90
+ categorized. For purposes of this Public License, the rights
91
+ specified in Section 2(b)(1)-(2) are not Copyright and Similar
92
+ Rights.
93
+ d. Effective Technological Measures means those measures that, in the
94
+ absence of proper authority, may not be circumvented under laws
95
+ fulfilling obligations under Article 11 of the WIPO Copyright
96
+ Treaty adopted on December 20, 1996, and/or similar international
97
+ agreements.
98
+
99
+ e. Exceptions and Limitations means fair use, fair dealing, and/or
100
+ any other exception or limitation to Copyright and Similar Rights
101
+ that applies to Your use of the Licensed Material.
102
+
103
+ f. Licensed Material means the artistic or literary work, database,
104
+ or other material to which the Licensor applied this Public
105
+ License.
106
+
107
+ g. Licensed Rights means the rights granted to You subject to the
108
+ terms and conditions of this Public License, which are limited to
109
+ all Copyright and Similar Rights that apply to Your use of the
110
+ Licensed Material and that the Licensor has authority to license.
111
+
112
+ h. Licensor means the individual(s) or entity(ies) granting rights
113
+ under this Public License.
114
+
115
+ i. NonCommercial means not primarily intended for or directed towards
116
+ commercial advantage or monetary compensation. For purposes of
117
+ this Public License, the exchange of the Licensed Material for
118
+ other material subject to Copyright and Similar Rights by digital
119
+ file-sharing or similar means is NonCommercial provided there is
120
+ no payment of monetary compensation in connection with the
121
+ exchange.
122
+
123
+ j. Share means to provide material to the public by any means or
124
+ process that requires permission under the Licensed Rights, such
125
+ as reproduction, public display, public performance, distribution,
126
+ dissemination, communication, or importation, and to make material
127
+ available to the public including in ways that members of the
128
+ public may access the material from a place and at a time
129
+ individually chosen by them.
130
+
131
+ k. Sui Generis Database Rights means rights other than copyright
132
+ resulting from Directive 96/9/EC of the European Parliament and of
133
+ the Council of 11 March 1996 on the legal protection of databases,
134
+ as amended and/or succeeded, as well as other essentially
135
+ equivalent rights anywhere in the world.
136
+
137
+ l. You means the individual or entity exercising the Licensed Rights
138
+ under this Public License. Your has a corresponding meaning.
139
+
140
+ Section 2 -- Scope.
141
+
142
+ a. License grant.
143
+
144
+ 1. Subject to the terms and conditions of this Public License,
145
+ the Licensor hereby grants You a worldwide, royalty-free,
146
+ non-sublicensable, non-exclusive, irrevocable license to
147
+ exercise the Licensed Rights in the Licensed Material to:
148
+
149
+ a. reproduce and Share the Licensed Material, in whole or
150
+ in part, for NonCommercial purposes only; and
151
+
152
+ b. produce, reproduce, and Share Adapted Material for
153
+ NonCommercial purposes only.
154
+
155
+ 2. Exceptions and Limitations. For the avoidance of doubt, where
156
+ Exceptions and Limitations apply to Your use, this Public
157
+ License does not apply, and You do not need to comply with
158
+ its terms and conditions.
159
+
160
+ 3. Term. The term of this Public License is specified in Section
161
+ 6(a).
162
+
163
+ 4. Media and formats; technical modifications allowed. The
164
+ Licensor authorizes You to exercise the Licensed Rights in
165
+ all media and formats whether now known or hereafter created,
166
+ and to make technical modifications necessary to do so. The
167
+ Licensor waives and/or agrees not to assert any right or
168
+ authority to forbid You from making technical modifications
169
+ necessary to exercise the Licensed Rights, including
170
+ technical modifications necessary to circumvent Effective
171
+ Technological Measures. For purposes of this Public License,
172
+ simply making modifications authorized by this Section 2(a)
173
+ (4) never produces Adapted Material.
174
+
175
+ 5. Downstream recipients.
176
+
177
+ a. Offer from the Licensor -- Licensed Material. Every
178
+ recipient of the Licensed Material automatically
179
+ receives an offer from the Licensor to exercise the
180
+ Licensed Rights under the terms and conditions of this
181
+ Public License.
182
+
183
+ b. No downstream restrictions. You may not offer or impose
184
+ any additional or different terms or conditions on, or
185
+ apply any Effective Technological Measures to, the
186
+ Licensed Material if doing so restricts exercise of the
187
+ Licensed Rights by any recipient of the Licensed
188
+ Material.
189
+
190
+ 6. No endorsement. Nothing in this Public License constitutes or
191
+ may be construed as permission to assert or imply that You
192
+ are, or that Your use of the Licensed Material is, connected
193
+ with, or sponsored, endorsed, or granted official status by,
194
+ the Licensor or others designated to receive attribution as
195
+ provided in Section 3(a)(1)(A)(i).
196
+
197
+ b. Other rights.
198
+
199
+ 1. Moral rights, such as the right of integrity, are not
200
+ licensed under this Public License, nor are publicity,
201
+ privacy, and/or other similar personality rights; however, to
202
+ the extent possible, the Licensor waives and/or agrees not to
203
+ assert any such rights held by the Licensor to the limited
204
+ extent necessary to allow You to exercise the Licensed
205
+ Rights, but not otherwise.
206
+
207
+ 2. Patent and trademark rights are not licensed under this
208
+ Public License.
209
+
210
+ 3. To the extent possible, the Licensor waives any right to
211
+ collect royalties from You for the exercise of the Licensed
212
+ Rights, whether directly or through a collecting society
213
+ under any voluntary or waivable statutory or compulsory
214
+ licensing scheme. In all other cases the Licensor expressly
215
+ reserves any right to collect such royalties, including when
216
+ the Licensed Material is used other than for NonCommercial
217
+ purposes.
218
+
219
+ Section 3 -- License Conditions.
220
+
221
+ Your exercise of the Licensed Rights is expressly made subject to the
222
+ following conditions.
223
+
224
+ a. Attribution.
225
+
226
+ 1. If You Share the Licensed Material (including in modified
227
+ form), You must:
228
+
229
+ a. retain the following if it is supplied by the Licensor
230
+ with the Licensed Material:
231
+
232
+ i. identification of the creator(s) of the Licensed
233
+ Material and any others designated to receive
234
+ attribution, in any reasonable manner requested by
235
+ the Licensor (including by pseudonym if
236
+ designated);
237
+
238
+ ii. a copyright notice;
239
+
240
+ iii. a notice that refers to this Public License;
241
+
242
+ iv. a notice that refers to the disclaimer of
243
+ warranties;
244
+
245
+ v. a URI or hyperlink to the Licensed Material to the
246
+ extent reasonably practicable;
247
+
248
+ b. indicate if You modified the Licensed Material and
249
+ retain an indication of any previous modifications; and
250
+
251
+ c. indicate the Licensed Material is licensed under this
252
+ Public License, and include the text of, or the URI or
253
+ hyperlink to, this Public License.
254
+
255
+ 2. You may satisfy the conditions in Section 3(a)(1) in any
256
+ reasonable manner based on the medium, means, and context in
257
+ which You Share the Licensed Material. For example, it may be
258
+ reasonable to satisfy the conditions by providing a URI or
259
+ hyperlink to a resource that includes the required
260
+ information.
261
+
262
+ 3. If requested by the Licensor, You must remove any of the
263
+ information required by Section 3(a)(1)(A) to the extent
264
+ reasonably practicable.
265
+
266
+ 4. If You Share Adapted Material You produce, the Adapter's
267
+ License You apply must not prevent recipients of the Adapted
268
+ Material from complying with this Public License.
269
+
270
+ Section 4 -- Sui Generis Database Rights.
271
+
272
+ Where the Licensed Rights include Sui Generis Database Rights that
273
+ apply to Your use of the Licensed Material:
274
+
275
+ a. for the avoidance of doubt, Section 2(a)(1) grants You the right
276
+ to extract, reuse, reproduce, and Share all or a substantial
277
+ portion of the contents of the database for NonCommercial purposes
278
+ only;
279
+
280
+ b. if You include all or a substantial portion of the database
281
+ contents in a database in which You have Sui Generis Database
282
+ Rights, then the database in which You have Sui Generis Database
283
+ Rights (but not its individual contents) is Adapted Material; and
284
+
285
+ c. You must comply with the conditions in Section 3(a) if You Share
286
+ all or a substantial portion of the contents of the database.
287
+
288
+ For the avoidance of doubt, this Section 4 supplements and does not
289
+ replace Your obligations under this Public License where the Licensed
290
+ Rights include other Copyright and Similar Rights.
291
+
292
+ Section 5 -- Disclaimer of Warranties and Limitation of Liability.
293
+
294
+ a. UNLESS OTHERWISE SEPARATELY UNDERTAKEN BY THE LICENSOR, TO THE
295
+ EXTENT POSSIBLE, THE LICENSOR OFFERS THE LICENSED MATERIAL AS-IS
296
+ AND AS-AVAILABLE, AND MAKES NO REPRESENTATIONS OR WARRANTIES OF
297
+ ANY KIND CONCERNING THE LICENSED MATERIAL, WHETHER EXPRESS,
298
+ IMPLIED, STATUTORY, OR OTHER. THIS INCLUDES, WITHOUT LIMITATION,
299
+ WARRANTIES OF TITLE, MERCHANTABILITY, FITNESS FOR A PARTICULAR
300
+ PURPOSE, NON-INFRINGEMENT, ABSENCE OF LATENT OR OTHER DEFECTS,
301
+ ACCURACY, OR THE PRESENCE OR ABSENCE OF ERRORS, WHETHER OR NOT
302
+ KNOWN OR DISCOVERABLE. WHERE DISCLAIMERS OF WARRANTIES ARE NOT
303
+ ALLOWED IN FULL OR IN PART, THIS DISCLAIMER MAY NOT APPLY TO YOU.
304
+
305
+ b. TO THE EXTENT POSSIBLE, IN NO EVENT WILL THE LICENSOR BE LIABLE
306
+ TO YOU ON ANY LEGAL THEORY (INCLUDING, WITHOUT LIMITATION,
307
+ NEGLIGENCE) OR OTHERWISE FOR ANY DIRECT, SPECIAL, INDIRECT,
308
+ INCIDENTAL, CONSEQUENTIAL, PUNITIVE, EXEMPLARY, OR OTHER LOSSES,
309
+ COSTS, EXPENSES, OR DAMAGES ARISING OUT OF THIS PUBLIC LICENSE OR
310
+ USE OF THE LICENSED MATERIAL, EVEN IF THE LICENSOR HAS BEEN
311
+ ADVISED OF THE POSSIBILITY OF SUCH LOSSES, COSTS, EXPENSES, OR
312
+ DAMAGES. WHERE A LIMITATION OF LIABILITY IS NOT ALLOWED IN FULL OR
313
+ IN PART, THIS LIMITATION MAY NOT APPLY TO YOU.
314
+
315
+ c. The disclaimer of warranties and limitation of liability provided
316
+ above shall be interpreted in a manner that, to the extent
317
+ possible, most closely approximates an absolute disclaimer and
318
+ waiver of all liability.
319
+
320
+ Section 6 -- Term and Termination.
321
+
322
+ a. This Public License applies for the term of the Copyright and
323
+ Similar Rights licensed here. However, if You fail to comply with
324
+ this Public License, then Your rights under this Public License
325
+ terminate automatically.
326
+
327
+ b. Where Your right to use the Licensed Material has terminated under
328
+ Section 6(a), it reinstates:
329
+
330
+ 1. automatically as of the date the violation is cured, provided
331
+ it is cured within 30 days of Your discovery of the
332
+ violation; or
333
+
334
+ 2. upon express reinstatement by the Licensor.
335
+
336
+ For the avoidance of doubt, this Section 6(b) does not affect any
337
+ right the Licensor may have to seek remedies for Your violations
338
+ of this Public License.
339
+
340
+ c. For the avoidance of doubt, the Licensor may also offer the
341
+ Licensed Material under separate terms or conditions or stop
342
+ distributing the Licensed Material at any time; however, doing so
343
+ will not terminate this Public License.
344
+
345
+ d. Sections 1, 5, 6, 7, and 8 survive termination of this Public
346
+ License.
347
+
348
+ Section 7 -- Other Terms and Conditions.
349
+
350
+ a. The Licensor shall not be bound by any additional or different
351
+ terms or conditions communicated by You unless expressly agreed.
352
+
353
+ b. Any arrangements, understandings, or agreements regarding the
354
+ Licensed Material not stated herein are separate from and
355
+ independent of the terms and conditions of this Public License.
356
+
357
+ Section 8 -- Interpretation.
358
+
359
+ a. For the avoidance of doubt, this Public License does not, and
360
+ shall not be interpreted to, reduce, limit, restrict, or impose
361
+ conditions on any use of the Licensed Material that could lawfully
362
+ be made without permission under this Public License.
363
+
364
+ b. To the extent possible, if any provision of this Public License is
365
+ deemed unenforceable, it shall be automatically reformed to the
366
+ minimum extent necessary to make it enforceable. If the provision
367
+ cannot be reformed, it shall be severed from this Public License
368
+ without affecting the enforceability of the remaining terms and
369
+ conditions.
370
+
371
+ c. No term or condition of this Public License will be waived and no
372
+ failure to comply consented to unless expressly agreed to by the
373
+ Licensor.
374
+
375
+ d. Nothing in this Public License constitutes or may be interpreted
376
+ as a limitation upon, or waiver of, any privileges and immunities
377
+ that apply to the Licensor or You, including from the legal
378
+ processes of any jurisdiction or authority.
379
+
380
+ =======================================================================
381
+
382
+ Creative Commons is not a party to its public
383
+ licenses. Notwithstanding, Creative Commons may elect to apply one of
384
+ its public licenses to material it publishes and in those instances
385
+ will be considered the “Licensor.” The text of the Creative Commons
386
+ public licenses is dedicated to the public domain under the CC0 Public
387
+ Domain Dedication. Except for the limited purpose of indicating that
388
+ material is shared under a Creative Commons public license or as
389
+ otherwise permitted by the Creative Commons policies published at
390
+ creativecommons.org/policies, Creative Commons does not authorize the
391
+ use of the trademark "Creative Commons" or any other trademark or logo
392
+ of Creative Commons without its prior written consent including,
393
+ without limitation, in connection with any unauthorized modifications
394
+ to any of its public licenses or any other arrangements,
395
+ understandings, or agreements concerning use of licensed material. For
396
+ the avoidance of doubt, this paragraph does not form part of the
397
+ public licenses.
398
+
399
+ Creative Commons may be contacted at creativecommons.org.
README.md CHANGED
@@ -1,199 +1,89 @@
1
- ---
2
- library_name: transformers
3
- tags: []
4
- ---
5
 
6
- # Model Card for Model ID
7
 
8
- <!-- Provide a quick summary of what the model is/does. -->
9
 
 
 
 
 
10
 
11
 
12
- ## Model Details
13
 
14
- ### Model Description
15
 
16
- <!-- Provide a longer summary of what this model is. -->
17
 
18
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
 
19
 
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
 
28
- ### Model Sources [optional]
 
29
 
30
- <!-- Provide the basic links for the model. -->
31
 
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
 
36
- ## Uses
 
 
 
 
37
 
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
 
39
 
40
- ### Direct Use
 
 
41
 
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
 
44
- [More Information Needed]
45
 
46
- ### Downstream Use [optional]
47
 
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
 
50
- [More Information Needed]
 
51
 
52
- ### Out-of-Scope Use
 
 
 
53
 
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
 
 
 
 
 
 
 
55
 
56
- [More Information Needed]
57
 
58
- ## Bias, Risks, and Limitations
59
 
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
 
62
- [More Information Needed]
63
 
64
- ### Recommendations
65
 
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
 
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
 
 
 
 
 
 
 
69
 
70
- ## How to Get Started with the Model
71
 
72
- Use the code below to get started with the model.
73
-
74
- [More Information Needed]
75
-
76
- ## Training Details
77
-
78
- ### Training Data
79
-
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
-
82
- [More Information Needed]
83
-
84
- ### Training Procedure
85
-
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
-
88
- #### Preprocessing [optional]
89
-
90
- [More Information Needed]
91
-
92
-
93
- #### Training Hyperparameters
94
-
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
-
97
- #### Speeds, Sizes, Times [optional]
98
-
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
-
101
- [More Information Needed]
102
-
103
- ## Evaluation
104
-
105
- <!-- This section describes the evaluation protocols and provides the results. -->
106
-
107
- ### Testing Data, Factors & Metrics
108
-
109
- #### Testing Data
110
-
111
- <!-- This should link to a Dataset Card if possible. -->
112
-
113
- [More Information Needed]
114
-
115
- #### Factors
116
-
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
-
119
- [More Information Needed]
120
-
121
- #### Metrics
122
-
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
-
125
- [More Information Needed]
126
-
127
- ### Results
128
-
129
- [More Information Needed]
130
-
131
- #### Summary
132
-
133
-
134
-
135
- ## Model Examination [optional]
136
-
137
- <!-- Relevant interpretability work for the model goes here -->
138
-
139
- [More Information Needed]
140
-
141
- ## Environmental Impact
142
-
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
-
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
-
147
- - **Hardware Type:** [More Information Needed]
148
- - **Hours used:** [More Information Needed]
149
- - **Cloud Provider:** [More Information Needed]
150
- - **Compute Region:** [More Information Needed]
151
- - **Carbon Emitted:** [More Information Needed]
152
-
153
- ## Technical Specifications [optional]
154
-
155
- ### Model Architecture and Objective
156
-
157
- [More Information Needed]
158
-
159
- ### Compute Infrastructure
160
-
161
- [More Information Needed]
162
-
163
- #### Hardware
164
-
165
- [More Information Needed]
166
-
167
- #### Software
168
-
169
- [More Information Needed]
170
-
171
- ## Citation [optional]
172
-
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
-
175
- **BibTeX:**
176
-
177
- [More Information Needed]
178
-
179
- **APA:**
180
-
181
- [More Information Needed]
182
-
183
- ## Glossary [optional]
184
-
185
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
-
187
- [More Information Needed]
188
-
189
- ## More Information [optional]
190
-
191
- [More Information Needed]
192
-
193
- ## Model Card Authors [optional]
194
-
195
- [More Information Needed]
196
-
197
- ## Model Card Contact
198
-
199
- [More Information Needed]
 
1
+ # [ECCV 2024] VFusion3D: Learning Scalable 3D Generative Models from Video Diffusion Models
 
 
 
2
 
3
+ [Porject page](https://junlinhan.github.io/projects/vfusion3d.html), [Paper link](https://arxiv.org/abs/2403.12034)
4
 
5
+ VFusion3D is a large, feed-forward 3D generative model trained with a small amount of 3D data and a large volume of synthetic multi-view data. It is the first work exploring scalable 3D generative/reconstruction models as a step towards a 3D foundation.
6
 
7
+ [VFusion3D: Learning Scalable 3D Generative Models from Video Diffusion Models](https://junlinhan.github.io/projects/vfusion3d.html)<br>
8
+ [Junlin Han](https://junlinhan.github.io/), [Filippos Kokkinos](https://www.fkokkinos.com/), [Philip Torr](https://www.robots.ox.ac.uk/~phst/)<br>
9
+ GenAI, Meta and TVG, University of Oxford<br>
10
+ European Conference on Computer Vision (ECCV), 2024
11
 
12
 
13
+ ## News
14
 
15
+ - [25.07.2024] Release weights and inference code for VFusion3D.
16
 
17
+ ## Results and Comparisons
18
 
19
+ ### 3D Generation Results
20
+ <img src='images/gif1.gif' width=950>
21
 
22
+ <img src='images/gif2.gif' width=950>
 
 
 
 
 
 
23
 
24
+ ### User Study Results
25
+ <img src='images/user.png' width=950>
26
 
 
27
 
28
+ ## Setup
 
 
29
 
30
+ ### Installation
31
+ ```
32
+ git clone https://github.com/facebookresearch/vfusion3d
33
+ cd vfusion3d
34
+ ```
35
 
36
+ ### Environment
37
+ We provide a simple installation script that, by default, sets up a conda environment with Python 3.8.19, PyTorch 2.3, and CUDA 12.1. Similar package versions should also work.
38
 
39
+ ```
40
+ source install.sh
41
+ ```
42
 
43
+ ## Quick Start
44
 
45
+ ### Pretrained Models
46
 
47
+ - Model weights are available here [Google Drive](https://drive.google.com/file/d/1b-KKSh9VquJdzmXzZBE4nKbXnbeua42X/view?usp=sharing). Please download it and put it inside ./checkpoints/
48
 
 
49
 
50
+ ### Prepare Images
51
+ - We put some sample inputs under `assets/40_prompt_images`, which is the 40 MVDream prompt images used in the paper. Results of them are also provided under `results/40_prompt_images_provided`.
52
 
53
+ ### Inference
54
+ - Run the inference script to get 3D assets.
55
+ - You may specify which form of output to generate by setting the flags `--export_video` and `--export_mesh`.
56
+ - Change `--source_path` and `--dump_path` if you want to run it on other image folders.
57
 
58
+ ```
59
+ # Example usages
60
+ # Render a video
61
+ python -m lrm.inferrer --export_video --resume ./checkpoints/vfusion3dckpt
62
+
63
+ # Export mesh
64
+ python -m lrm.inferrer --export_mesh --resume ./checkpoints/vfusion3dckpt
65
+ ```
66
 
 
67
 
68
+ ## Acknowledgement
69
 
70
+ - This inference code of VFusion3D heavily borrows from [OpenLRM](https://github.com/3DTopia/OpenLRM).
71
 
72
+ ## Citation
73
 
74
+ If you find this work useful, please cite us:
75
 
 
76
 
77
+ ```
78
+ @article{han2024vfusion3d,
79
+ title={VFusion3D: Learning Scalable 3D Generative Models from Video Diffusion Models},
80
+ author={Junlin Han and Filippos Kokkinos and Philip Torr},
81
+ journal={European Conference on Computer Vision (ECCV)},
82
+ year={2024}
83
+ }
84
+ ```
85
 
86
+ ## License
87
 
88
+ - The majority of VFusion3D is licensed under CC-BY-NC, however portions of the project are available under separate license terms: OpenLRM as a whole is licensed under the Apache License, Version 2.0, while certain components are covered by NVIDIA's proprietary license.
89
+ - The model weights of VFusion3D is also licensed under CC-BY-NC.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ from .modeling import LRMGenerator, LRMGeneratorConfig
assets/40_prompt_images/A 3D scan of AK47, weapon.jpeg ADDED
assets/40_prompt_images/A DSLR photo of Sydney Opera House.jpg ADDED
assets/40_prompt_images/A bald eagle carved out of wood.jpg ADDED
assets/40_prompt_images/A bulldog wearing a black pirate hat.jpeg ADDED
assets/40_prompt_images/A crab, low poly.jpg ADDED
assets/40_prompt_images/A photo of a horse walking.jpeg ADDED
assets/40_prompt_images/A pig wearing a backpack.jpeg ADDED
assets/40_prompt_images/A product photo of a toy tank.jpg ADDED
assets/40_prompt_images/A see no evil monkey on a kick drum.jpg ADDED
assets/40_prompt_images/A statue of angel, blender.jpg ADDED
assets/40_prompt_images/Corgi riding a rocket.jpeg ADDED
assets/40_prompt_images/Daenerys Targaryen from game of throne.jpg ADDED
assets/40_prompt_images/Darth Vader helmet,g highly detailed.jpg ADDED
assets/40_prompt_images/Dragon armor.jpeg ADDED
assets/40_prompt_images/Fisherman House, cute, cartoon, blender, stylized.jpg ADDED
assets/40_prompt_images/Flying Dragon, highly detailed, breathing fire.jpeg ADDED
assets/40_prompt_images/Handpainted watercolor windmill, hand-painted.jpg ADDED
assets/40_prompt_images/Katana.jpeg ADDED
assets/40_prompt_images/Little italian town, hand-painted style.jpg ADDED
assets/40_prompt_images/Mr Bean Cartoon doing a T Pose.jpg ADDED
assets/40_prompt_images/Pedestal Fan (White).jpeg ADDED
assets/40_prompt_images/Pikachu with hat.jpg ADDED
assets/40_prompt_images/Samurai koala bear.jpg ADDED
assets/40_prompt_images/TRUMP figure.jpg ADDED
assets/40_prompt_images/Viking axe, fantasy, weapon, blender, 8k, HD.jpg ADDED
assets/40_prompt_images/a DSLR photo of a frog wearing a sweater.jpg ADDED
assets/40_prompt_images/a DSLR photo of a ghost eating a hamburger.jpg ADDED
assets/40_prompt_images/a DSLR photo of a peacock on a surfboard.jpeg ADDED
assets/40_prompt_images/a DSLR photo of a squirrel playing guitar.jpg ADDED
assets/40_prompt_images/a DSLR photo of an eggshell broken in two with an adorable chick standing next to it.jpeg ADDED
assets/40_prompt_images/an astronaut riding a horse.jpeg ADDED
assets/40_prompt_images/animal skull pile.jpg ADDED
assets/40_prompt_images/army Jacket, 3D scan.jpg ADDED
assets/40_prompt_images/baby yoda in the style of Mormookiee.jpg ADDED
assets/40_prompt_images/beautiful, intricate butterfly.jpg ADDED
assets/40_prompt_images/girl riding wolf, cute, cartoon, blender.jpg ADDED
assets/40_prompt_images/mecha vampire girl chibi.jpg ADDED
assets/40_prompt_images/military Mech, future, scifi.jpg ADDED
assets/40_prompt_images/motorcycle, scifi, blender.jpeg ADDED
assets/40_prompt_images/saber from fate stay night, 3D, girl, anime.jpeg ADDED
install.sh ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ # All rights reserved.
3
+ #
4
+ # This source code is licensed under the license found in the
5
+ # LICENSE file in the root directory of this source tree.
6
+
7
+ # This Script Assumes Python 3.8.19, CUDA 12.1. Similar package versions might still work but they are not tested.
8
+
9
+ conda deactivate
10
+
11
+ # Set environment variables
12
+ export ENV_NAME=vfusion3d
13
+ export PYTHON_VERSION=3.8.19
14
+ export CUDA_VERSION=12.1
15
+
16
+ # Create a new conda environment and activate it
17
+ conda create -n $ENV_NAME python=$PYTHON_VERSION
18
+ conda activate $ENV_NAME
19
+ conda install pytorch=2.3.0 torchvision==0.18.0 pytorch-cuda=$CUDA_VERSION -c pytorch -c nvidia
20
+ pip install transformers
21
+ pip install imageio[ffmpeg]
22
+ pip install PyMCubes
23
+ pip install trimesh
24
+ pip install rembg[gpu,cli]
25
+ pip install kiui
lrm/__init__.py ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ # All rights reserved.
3
+ #
4
+ # This source code is licensed under the license found in the
5
+ # LICENSE file in the root directory of this source tree.
lrm/cam_utils.py ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ # All rights reserved.
3
+ #
4
+ # This source code is licensed under the license found in the
5
+ # LICENSE file in the root directory of this source tree.
6
+
7
+
8
+ import torch
9
+ import numpy as np
10
+ import math
11
+
12
+ """
13
+ R: (N, 3, 3)
14
+ T: (N, 3)
15
+ E: (N, 4, 4)
16
+ vector: (N, 3)
17
+ """
18
+
19
+
20
+ def compose_extrinsic_R_T(R: torch.Tensor, T: torch.Tensor):
21
+ """
22
+ Compose the standard form extrinsic matrix from R and T.
23
+ Batched I/O.
24
+ """
25
+ RT = torch.cat((R, T.unsqueeze(-1)), dim=-1)
26
+ return compose_extrinsic_RT(RT)
27
+
28
+
29
+ def compose_extrinsic_RT(RT: torch.Tensor):
30
+ """
31
+ Compose the standard form extrinsic matrix from RT.
32
+ Batched I/O.
33
+ """
34
+ return torch.cat([
35
+ RT,
36
+ torch.tensor([[[0, 0, 0, 1]]], dtype=torch.float32).repeat(RT.shape[0], 1, 1).to(RT.device)
37
+ ], dim=1)
38
+
39
+
40
+ def decompose_extrinsic_R_T(E: torch.Tensor):
41
+ """
42
+ Decompose the standard extrinsic matrix into R and T.
43
+ Batched I/O.
44
+ """
45
+ RT = decompose_extrinsic_RT(E)
46
+ return RT[:, :, :3], RT[:, :, 3]
47
+
48
+
49
+ def decompose_extrinsic_RT(E: torch.Tensor):
50
+ """
51
+ Decompose the standard extrinsic matrix into RT.
52
+ Batched I/O.
53
+ """
54
+ return E[:, :3, :]
55
+
56
+
57
+ def get_normalized_camera_intrinsics(intrinsics: torch.Tensor):
58
+ """
59
+ intrinsics: (N, 3, 2), [[fx, fy], [cx, cy], [width, height]]
60
+ Return batched fx, fy, cx, cy
61
+ """
62
+ fx, fy = intrinsics[:, 0, 0], intrinsics[:, 0, 1]
63
+ cx, cy = intrinsics[:, 1, 0], intrinsics[:, 1, 1]
64
+ width, height = intrinsics[:, 2, 0], intrinsics[:, 2, 1]
65
+ fx, fy = fx / width, fy / height
66
+ cx, cy = cx / width, cy / height
67
+ return fx, fy, cx, cy
68
+
69
+
70
+ def build_camera_principle(RT: torch.Tensor, intrinsics: torch.Tensor):
71
+ """
72
+ RT: (N, 3, 4)
73
+ intrinsics: (N, 3, 2), [[fx, fy], [cx, cy], [width, height]]
74
+ """
75
+ fx, fy, cx, cy = get_normalized_camera_intrinsics(intrinsics)
76
+ return torch.cat([
77
+ RT.reshape(-1, 12),
78
+ fx.unsqueeze(-1), fy.unsqueeze(-1), cx.unsqueeze(-1), cy.unsqueeze(-1),
79
+ ], dim=-1)
80
+
81
+
82
+ def build_camera_standard(RT: torch.Tensor, intrinsics: torch.Tensor):
83
+ """
84
+ RT: (N, 3, 4)
85
+ intrinsics: (N, 3, 2), [[fx, fy], [cx, cy], [width, height]]
86
+ """
87
+ E = compose_extrinsic_RT(RT)
88
+ fx, fy, cx, cy = get_normalized_camera_intrinsics(intrinsics)
89
+ I = torch.stack([
90
+ torch.stack([fx, torch.zeros_like(fx), cx], dim=-1),
91
+ torch.stack([torch.zeros_like(fy), fy, cy], dim=-1),
92
+ torch.tensor([[0, 0, 1]], dtype=torch.float32, device=RT.device).repeat(RT.shape[0], 1),
93
+ ], dim=1)
94
+ return torch.cat([
95
+ E.reshape(-1, 16),
96
+ I.reshape(-1, 9),
97
+ ], dim=-1)
98
+
99
+
100
+ def center_looking_at_camera_pose(camera_position: torch.Tensor, look_at: torch.Tensor = None, up_world: torch.Tensor = None):
101
+ """
102
+ camera_position: (M, 3)
103
+ look_at: (3)
104
+ up_world: (3)
105
+ return: (M, 3, 4)
106
+ """
107
+ # by default, looking at the origin and world up is pos-z
108
+ if look_at is None:
109
+ look_at = torch.tensor([0, 0, 0], dtype=torch.float32)
110
+ if up_world is None:
111
+ up_world = torch.tensor([0, 0, 1], dtype=torch.float32)
112
+ look_at = look_at.unsqueeze(0).repeat(camera_position.shape[0], 1)
113
+ up_world = up_world.unsqueeze(0).repeat(camera_position.shape[0], 1)
114
+
115
+ z_axis = camera_position - look_at
116
+ z_axis = z_axis / z_axis.norm(dim=-1, keepdim=True)
117
+ x_axis = torch.cross(up_world, z_axis)
118
+ x_axis = x_axis / x_axis.norm(dim=-1, keepdim=True)
119
+ y_axis = torch.cross(z_axis, x_axis)
120
+ y_axis = y_axis / y_axis.norm(dim=-1, keepdim=True)
121
+ extrinsics = torch.stack([x_axis, y_axis, z_axis, camera_position], dim=-1)
122
+ return extrinsics
123
+
124
+ def get_surrounding_views(M, radius, elevation):
125
+ # convert spherical coordinates (radius, azimuth, elevation) to Cartesian coordinates (x, y, z).
126
+ camera_positions = []
127
+ rand_theta= np.random.uniform(0, np.pi/180)
128
+ elevation = math.radians(elevation)
129
+ for i in range(M):
130
+ theta = 2 * math.pi * i / M + rand_theta
131
+ x = radius * math.cos(theta) * math.cos(elevation)
132
+ y = radius * math.sin(theta) * math.cos(elevation)
133
+ z = radius * math.sin(elevation)
134
+ camera_positions.append([x, y, z])
135
+ camera_positions = torch.tensor(camera_positions, dtype=torch.float32)
136
+ extrinsics = center_looking_at_camera_pose(camera_positions)
137
+
138
+ return extrinsics
lrm/inferrer.py ADDED
@@ -0,0 +1,232 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import math
3
+ import os
4
+ import imageio
5
+ import mcubes
6
+ import trimesh
7
+ import numpy as np
8
+ import argparse
9
+ from torchvision.utils import save_image
10
+ from PIL import Image
11
+ import glob
12
+ from .models.generator import LRMGenerator # Make sure this import is correct
13
+ from .cam_utils import build_camera_principle, build_camera_standard, center_looking_at_camera_pose # Make sure this import is correct
14
+ from functools import partial
15
+ from rembg import remove, new_session
16
+ from kiui.op import recenter
17
+ import kiui
18
+
19
+ class LRMInferrer:
20
+ def __init__(self, model_name: str, resume: str):
21
+ print("Initializing LRMInferrer")
22
+ self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
23
+ _model_kwargs = {'camera_embed_dim': 1024, 'rendering_samples_per_ray': 128, 'transformer_dim': 1024, 'transformer_layers': 16, 'transformer_heads': 16, 'triplane_low_res': 32, 'triplane_high_res': 64, 'triplane_dim': 80, 'encoder_freeze': False}
24
+
25
+ self.model = self._build_model(_model_kwargs).eval().to(self.device)
26
+ checkpoint = torch.load(resume, map_location='cpu')
27
+ state_dict = checkpoint['model_state_dict']
28
+ self.model.load_state_dict(state_dict)
29
+ del checkpoint, state_dict
30
+ torch.cuda.empty_cache()
31
+
32
+ def __enter__(self):
33
+ print("Entering context")
34
+ return self
35
+
36
+ def __exit__(self, exc_type, exc_val, exc_tb):
37
+ print("Exiting context")
38
+ if exc_type:
39
+ print(f"Exception type: {exc_type}")
40
+ print(f"Exception value: {exc_val}")
41
+ print(f"Traceback: {exc_tb}")
42
+
43
+ def _build_model(self, model_kwargs):
44
+ print("Building model")
45
+ model = LRMGenerator(**model_kwargs).to(self.device)
46
+ print("Loaded model from checkpoint")
47
+ return model
48
+
49
+ @staticmethod
50
+ def get_surrounding_views(M, radius, elevation):
51
+ camera_positions = []
52
+ rand_theta = np.random.uniform(0, np.pi/180)
53
+ elevation = math.radians(elevation)
54
+ for i in range(M):
55
+ theta = 2 * math.pi * i / M + rand_theta
56
+ x = radius * math.cos(theta) * math.cos(elevation)
57
+ y = radius * math.sin(theta) * math.cos(elevation)
58
+ z = radius * math.sin(elevation)
59
+ camera_positions.append([x, y, z])
60
+ camera_positions = torch.tensor(camera_positions, dtype=torch.float32)
61
+ extrinsics = center_looking_at_camera_pose(camera_positions)
62
+ return extrinsics
63
+
64
+ @staticmethod
65
+ def _default_intrinsics():
66
+ fx = fy = 384
67
+ cx = cy = 256
68
+ w = h = 512
69
+ intrinsics = torch.tensor([
70
+ [fx, fy],
71
+ [cx, cy],
72
+ [w, h],
73
+ ], dtype=torch.float32)
74
+ return intrinsics
75
+
76
+ def _default_source_camera(self, batch_size: int = 1):
77
+ dist_to_center = 1.5
78
+ canonical_camera_extrinsics = torch.tensor([[
79
+ [0, 0, 1, 1],
80
+ [1, 0, 0, 0],
81
+ [0, 1, 0, 0],
82
+ ]], dtype=torch.float32)
83
+ canonical_camera_intrinsics = self._default_intrinsics().unsqueeze(0)
84
+ source_camera = build_camera_principle(canonical_camera_extrinsics, canonical_camera_intrinsics)
85
+ return source_camera.repeat(batch_size, 1)
86
+
87
+ def _default_render_cameras(self, batch_size: int = 1):
88
+ render_camera_extrinsics = self.get_surrounding_views(160, 1.5, 0)
89
+ render_camera_intrinsics = self._default_intrinsics().unsqueeze(0).repeat(render_camera_extrinsics.shape[0], 1, 1)
90
+ render_cameras = build_camera_standard(render_camera_extrinsics, render_camera_intrinsics)
91
+ return render_cameras.unsqueeze(0).repeat(batch_size, 1, 1)
92
+
93
+ @staticmethod
94
+ def images_to_video(images, output_path, fps, verbose=False):
95
+ os.makedirs(os.path.dirname(output_path), exist_ok=True)
96
+ frames = []
97
+ for i in range(images.shape[0]):
98
+ frame = (images[i].permute(1, 2, 0).cpu().numpy() * 255).astype(np.uint8)
99
+ assert frame.shape[0] == images.shape[2] and frame.shape[1] == images.shape[3], \
100
+ f"Frame shape mismatch: {frame.shape} vs {images.shape}"
101
+ assert frame.min() >= 0 and frame.max() <= 255, \
102
+ f"Frame value out of range: {frame.min()} ~ {frame.max()}"
103
+ frames.append(frame)
104
+ imageio.mimwrite(output_path, np.stack(frames), fps=fps)
105
+ if verbose:
106
+ print(f"Saved video to {output_path}")
107
+
108
+ def infer_single(self, image: torch.Tensor, render_size: int, mesh_size: int, export_video: bool, export_mesh: bool):
109
+ print("infer_single called")
110
+ mesh_thres = 1.0
111
+ chunk_size = 2
112
+ batch_size = 1
113
+
114
+ source_camera = self._default_source_camera(batch_size).to(self.device)
115
+ render_cameras = self._default_render_cameras(batch_size).to(self.device)
116
+
117
+ with torch.no_grad():
118
+ planes = self.model.forward(image, source_camera)
119
+ results = {}
120
+
121
+ if export_video:
122
+ print("Starting export_video")
123
+ frames = []
124
+ for i in range(0, render_cameras.shape[1], chunk_size):
125
+ print(f"Processing chunk {i} to {i + chunk_size}")
126
+ frames.append(
127
+ self.model.synthesizer(
128
+ planes,
129
+ render_cameras[:, i:i+chunk_size],
130
+ render_size,
131
+ render_size,
132
+ 0,
133
+ 0
134
+ )
135
+ )
136
+ frames = {
137
+ k: torch.cat([r[k] for r in frames], dim=1)
138
+ for k in frames[0].keys()
139
+ }
140
+ results.update({
141
+ 'frames': frames,
142
+ })
143
+ print("Finished export_video")
144
+
145
+ if export_mesh:
146
+ print("Starting export_mesh")
147
+ grid_out = self.model.synthesizer.forward_grid(
148
+ planes=planes,
149
+ grid_size=mesh_size,
150
+ )
151
+ vtx, faces = mcubes.marching_cubes(grid_out['sigma'].float().squeeze(0).squeeze(-1).cpu().numpy(), mesh_thres)
152
+ vtx = vtx / (mesh_size - 1) * 2 - 1
153
+ vtx_tensor = torch.tensor(vtx, dtype=torch.float32, device=self.device).unsqueeze(0)
154
+ vtx_colors = self.model.synthesizer.forward_points(planes, vtx_tensor)['rgb'].float().squeeze(0).cpu().numpy()
155
+ vtx_colors = (vtx_colors * 255).astype(np.uint8)
156
+ mesh = trimesh.Trimesh(vertices=vtx, faces=faces, vertex_colors=vtx_colors)
157
+ results.update({
158
+ 'mesh': mesh,
159
+ })
160
+ print("Finished export_mesh")
161
+
162
+ return results
163
+
164
+ def infer(self, source_image: str, dump_path: str, source_size: int, render_size: int, mesh_size: int, export_video: bool, export_mesh: bool):
165
+ print("infer called")
166
+ session = new_session("isnet-general-use")
167
+ rembg_remove = partial(remove, session=session)
168
+ image_name = os.path.basename(source_image)
169
+ uid = image_name.split('.')[0]
170
+
171
+ image = kiui.read_image(source_image, mode='uint8')
172
+ image = rembg_remove(image)
173
+ mask = rembg_remove(image, only_mask=True)
174
+ image = recenter(image, mask, border_ratio=0.20)
175
+ os.makedirs(dump_path, exist_ok=True)
176
+
177
+ image = torch.tensor(np.array(image)).permute(2, 0, 1).unsqueeze(0) / 255.0
178
+ if image.shape[1] == 4:
179
+ image = image[:, :3, ...] * image[:, 3:, ...] + (1 - image[:, 3:, ...])
180
+ image = torch.nn.functional.interpolate(image, size=(source_size, source_size), mode='bicubic', align_corners=True)
181
+ image = torch.clamp(image, 0, 1)
182
+ save_image(image, os.path.join(dump_path, f'{uid}.png'))
183
+
184
+ results = self.infer_single(
185
+ image.cuda(),
186
+ render_size=render_size,
187
+ mesh_size=mesh_size,
188
+ export_video=export_video,
189
+ export_mesh=export_mesh,
190
+ )
191
+
192
+ if 'frames' in results:
193
+ renderings = results['frames']
194
+ for k, v in renderings.items():
195
+ if k == 'images_rgb':
196
+ self.images_to_video(
197
+ v[0],
198
+ os.path.join(dump_path, f'{uid}.mp4'),
199
+ fps=40,
200
+ )
201
+ print(f"Export video success to {dump_path}")
202
+
203
+ if 'mesh' in results:
204
+ mesh = results['mesh']
205
+ mesh.export(os.path.join(dump_path, f'{uid}.obj'), 'obj')
206
+
207
+ if __name__ == '__main__':
208
+ parser = argparse.ArgumentParser()
209
+ parser.add_argument('--model_name', type=str, default='lrm-base-obj-v1')
210
+ parser.add_argument('--source_path', type=str, default='./assets/cat.png')
211
+ parser.add_argument('--dump_path', type=str, default='./results/single_image')
212
+ parser.add_argument('--source_size', type=int, default=512)
213
+ parser.add_argument('--render_size', type=int, default=384)
214
+ parser.add_argument('--mesh_size', type=int, default=512)
215
+ parser.add_argument('--export_video', action='store_true')
216
+ parser.add_argument('--export_mesh', action='store_true')
217
+ parser.add_argument('--resume', type=str, required=True, help='Path to a checkpoint to resume training from')
218
+ args = parser.parse_args()
219
+
220
+ with LRMInferrer(model_name=args.model_name, resume=args.resume) as inferrer:
221
+ with torch.autocast(device_type="cuda", cache_enabled=False, dtype=torch.float32):
222
+ print("Start inference for image:", args.source_path)
223
+ inferrer.infer(
224
+ source_image=args.source_path,
225
+ dump_path=args.dump_path,
226
+ source_size=args.source_size,
227
+ render_size=args.render_size,
228
+ mesh_size=args.mesh_size,
229
+ export_video=args.export_video,
230
+ export_mesh=args.export_mesh,
231
+ )
232
+ print("Finished inference for image:", args.source_path)
lrm/models/__init__.py ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ # All rights reserved.
3
+ #
4
+ # This source code is licensed under the license found in the
5
+ # LICENSE file in the root directory of this source tree.