Updates for version 0.7.1

This commit is contained in:
Jeremy Francis Reizenstein 2022-10-23 09:41:42 -07:00
parent 27dc9dc21d
commit 45d1b39f1c
14 changed files with 481 additions and 545 deletions

View File

@ -107,7 +107,7 @@ The intersection shape is formed by the convex hull from the intersection points
<h2><a class="anchor" aria-hidden="true" id="usage-and-code"></a><a href="#usage-and-code" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Usage and Code</h2>
<pre><code class="hljs css language-python"><span class="hljs-keyword">from</span> pytorch3d.ops <span class="hljs-keyword">import</span> box3d_overlap
<span class="hljs-comment"># Assume inputs: boxes1 (M, 8, 3) and boxes2 (N, 8, 3)</span>
intersection_vol, iou_3d = box3d_overal(boxes1, boxes2)
intersection_vol, iou_3d = box3d_overlap(boxes1, boxes2)
</code></pre>
<p>For more details, read <a href="https://github.com/facebookresearch/pytorch3d/blob/main/pytorch3d/ops/iou_box3d.py">iou_box3d.py</a>.</p>
<p>Note that our implementation is not differentiable as of now. We plan to add gradient support soon.</p>
@ -122,4 +122,4 @@ intersection_vol, iou_3d = box3d_overal(boxes1, boxes2)
year = {<span class="hljs-number">2020</span>},
}
</code></pre>
</span></div></article></div><div class="docLastUpdate"><em>Last updated by Georgia Gkioxari</em></div><div class="docs-prevnext"><a class="docs-prev button" href="/docs/cubify"><span class="arrow-prev"></span><span>Cubify</span></a><a class="docs-next button" href="/docs/visualization"><span>Plotly Visualization</span><span class="arrow-next"></span></a></div></div></div><nav class="onPageNav"><ul class="toc-headings"><li><a href="#description">Description</a></li><li><a href="#comparison-with-other-algorithms">Comparison With Other Algorithms</a></li><li><a href="#usage-and-code">Usage and Code</a></li><li><a href="#cite">Cite</a></li></ul></nav></div><footer class="nav-footer" id="footer"><section class="sitemap"><div class="footerSection"><div class="social"><a class="github-button" href="https://github.com/facebookresearch/pytorch3d" data-count-href="https://github.com/facebookresearch/pytorch3d/stargazers" data-show-count="true" data-count-aria-label="# stargazers on GitHub" aria-label="Star PyTorch3D on GitHub">pytorch3d</a></div></div></section><a href="https://opensource.facebook.com/" target="_blank" rel="noreferrer noopener" class="fbOpenSource"><img src="/img/oss_logo.png" alt="Facebook Open Source" width="170" height="45"/></a><section class="copyright">Copyright © 2022 Meta Platforms, Inc<br/>Legal:<a href="https://opensource.facebook.com/legal/privacy/" target="_blank" rel="noreferrer noopener">Privacy</a><a href="https://opensource.facebook.com/legal/terms/" target="_blank" rel="noreferrer noopener">Terms</a></section></footer></div></body></html>
</span></div></article></div><div class="docLastUpdate"><em>Last updated by Ji Hou</em></div><div class="docs-prevnext"><a class="docs-prev button" href="/docs/cubify"><span class="arrow-prev"></span><span>Cubify</span></a><a class="docs-next button" href="/docs/visualization"><span>Plotly Visualization</span><span class="arrow-next"></span></a></div></div></div><nav class="onPageNav"><ul class="toc-headings"><li><a href="#description">Description</a></li><li><a href="#comparison-with-other-algorithms">Comparison With Other Algorithms</a></li><li><a href="#usage-and-code">Usage and Code</a></li><li><a href="#cite">Cite</a></li></ul></nav></div><footer class="nav-footer" id="footer"><section class="sitemap"><div class="footerSection"><div class="social"><a class="github-button" href="https://github.com/facebookresearch/pytorch3d" data-count-href="https://github.com/facebookresearch/pytorch3d/stargazers" data-show-count="true" data-count-aria-label="# stargazers on GitHub" aria-label="Star PyTorch3D on GitHub">pytorch3d</a></div></div></section><a href="https://opensource.facebook.com/" target="_blank" rel="noreferrer noopener" class="fbOpenSource"><img src="/img/oss_logo.png" alt="Facebook Open Source" width="170" height="45"/></a><section class="copyright">Copyright © 2022 Meta Platforms, Inc<br/>Legal:<a href="https://opensource.facebook.com/legal/privacy/" target="_blank" rel="noreferrer noopener">Privacy</a><a href="https://opensource.facebook.com/legal/terms/" target="_blank" rel="noreferrer noopener">Terms</a></section></footer></div></body></html>

View File

@ -107,7 +107,7 @@ The intersection shape is formed by the convex hull from the intersection points
<h2><a class="anchor" aria-hidden="true" id="usage-and-code"></a><a href="#usage-and-code" aria-hidden="true" class="hash-link"><svg class="hash-link-icon" aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a>Usage and Code</h2>
<pre><code class="hljs css language-python"><span class="hljs-keyword">from</span> pytorch3d.ops <span class="hljs-keyword">import</span> box3d_overlap
<span class="hljs-comment"># Assume inputs: boxes1 (M, 8, 3) and boxes2 (N, 8, 3)</span>
intersection_vol, iou_3d = box3d_overal(boxes1, boxes2)
intersection_vol, iou_3d = box3d_overlap(boxes1, boxes2)
</code></pre>
<p>For more details, read <a href="https://github.com/facebookresearch/pytorch3d/blob/main/pytorch3d/ops/iou_box3d.py">iou_box3d.py</a>.</p>
<p>Note that our implementation is not differentiable as of now. We plan to add gradient support soon.</p>
@ -122,4 +122,4 @@ intersection_vol, iou_3d = box3d_overal(boxes1, boxes2)
year = {<span class="hljs-number">2020</span>},
}
</code></pre>
</span></div></article></div><div class="docLastUpdate"><em>Last updated by Georgia Gkioxari</em></div><div class="docs-prevnext"><a class="docs-prev button" href="/docs/cubify"><span class="arrow-prev"></span><span>Cubify</span></a><a class="docs-next button" href="/docs/visualization"><span>Plotly Visualization</span><span class="arrow-next"></span></a></div></div></div><nav class="onPageNav"><ul class="toc-headings"><li><a href="#description">Description</a></li><li><a href="#comparison-with-other-algorithms">Comparison With Other Algorithms</a></li><li><a href="#usage-and-code">Usage and Code</a></li><li><a href="#cite">Cite</a></li></ul></nav></div><footer class="nav-footer" id="footer"><section class="sitemap"><div class="footerSection"><div class="social"><a class="github-button" href="https://github.com/facebookresearch/pytorch3d" data-count-href="https://github.com/facebookresearch/pytorch3d/stargazers" data-show-count="true" data-count-aria-label="# stargazers on GitHub" aria-label="Star PyTorch3D on GitHub">pytorch3d</a></div></div></section><a href="https://opensource.facebook.com/" target="_blank" rel="noreferrer noopener" class="fbOpenSource"><img src="/img/oss_logo.png" alt="Facebook Open Source" width="170" height="45"/></a><section class="copyright">Copyright © 2022 Meta Platforms, Inc<br/>Legal:<a href="https://opensource.facebook.com/legal/privacy/" target="_blank" rel="noreferrer noopener">Privacy</a><a href="https://opensource.facebook.com/legal/terms/" target="_blank" rel="noreferrer noopener">Terms</a></section></footer></div></body></html>
</span></div></article></div><div class="docLastUpdate"><em>Last updated by Ji Hou</em></div><div class="docs-prevnext"><a class="docs-prev button" href="/docs/cubify"><span class="arrow-prev"></span><span>Cubify</span></a><a class="docs-next button" href="/docs/visualization"><span>Plotly Visualization</span><span class="arrow-next"></span></a></div></div></div><nav class="onPageNav"><ul class="toc-headings"><li><a href="#description">Description</a></li><li><a href="#comparison-with-other-algorithms">Comparison With Other Algorithms</a></li><li><a href="#usage-and-code">Usage and Code</a></li><li><a href="#cite">Cite</a></li></ul></nav></div><footer class="nav-footer" id="footer"><section class="sitemap"><div class="footerSection"><div class="social"><a class="github-button" href="https://github.com/facebookresearch/pytorch3d" data-count-href="https://github.com/facebookresearch/pytorch3d/stargazers" data-show-count="true" data-count-aria-label="# stargazers on GitHub" aria-label="Star PyTorch3D on GitHub">pytorch3d</a></div></div></section><a href="https://opensource.facebook.com/" target="_blank" rel="noreferrer noopener" class="fbOpenSource"><img src="/img/oss_logo.png" alt="Facebook Open Source" width="170" height="45"/></a><section class="copyright">Copyright © 2022 Meta Platforms, Inc<br/>Legal:<a href="https://opensource.facebook.com/legal/privacy/" target="_blank" rel="noreferrer noopener">Privacy</a><a href="https://opensource.facebook.com/legal/terms/" target="_blank" rel="noreferrer noopener">Terms</a></section></footer></div></body></html>

File diff suppressed because it is too large Load Diff

View File

@ -186,9 +186,9 @@ class MyConfigurable(Configurable):
# In[ ]:
# expand_args_fields must be called on an object before it is instantiated.
# A warning is raised if this is missed, but it is possible to not notice the warning.
# It modifies the class like @dataclass
# The expand_args_fields function modifies the class like @dataclasses.dataclass.
# If it has not been called on a Configurable object before it has been instantiated, it will
# be called automatically.
expand_args_fields(MyConfigurable)
my_configurable_instance = MyConfigurable(a=18)
assert my_configurable_instance.d == 16
@ -197,7 +197,7 @@ assert my_configurable_instance.d == 16
# In[ ]:
# get_default_args calls expand_args_fields automatically
# get_default_args also calls expand_args_fields automatically
our_structured = get_default_args(MyConfigurable)
assert isinstance(our_structured, DictConfig)
print(OmegaConf.to_yaml(our_structured))
@ -357,7 +357,6 @@ class MyLinear(torch.nn.Module, Configurable):
# In[ ]:
expand_args_fields(MyLinear)
my_linear = MyLinear()
input = torch.zeros(2)
output = my_linear(input)
@ -415,7 +414,6 @@ class Out(Configurable):
# In[ ]:
expand_args_fields(Out)
out2 = Out(inner_class_type="UserImplementedInner")
print(out2.inner)
@ -450,7 +448,6 @@ class LargeComponent(Configurable):
# In[ ]:
expand_args_fields(LargeComponent)
large_component = LargeComponent()
assert large_component.apply(3) == 4
print(OmegaConf.to_yaml(LargeComponent))
@ -491,7 +488,6 @@ class LargeComponent(Configurable):
# In[ ]:
expand_args_fields(LargeComponent)
large_component = LargeComponent()
assert large_component.apply(3) == 4
print(OmegaConf.to_yaml(LargeComponent))
@ -506,7 +502,6 @@ print(OmegaConf.to_yaml(LargeComponent))
# ## Appendix: gotchas ⚠️
#
# * Omitting to define `__post_init__` or not calling `run_auto_creation` in it.
# * Using a configurable class without calling get_default_args or expand_args_fields on it.
# * Omitting a type annotation on a field. For example, writing
# ```
# subcomponent_class_type = "SubComponent"

View File

@ -145,10 +145,9 @@
"from pytorch3d.implicitron.dataset.dataset_base import FrameData\n",
"from pytorch3d.implicitron.dataset.rendered_mesh_dataset_map_provider import RenderedMeshDatasetMapProvider\n",
"from pytorch3d.implicitron.models.generic_model import GenericModel\n",
"from pytorch3d.implicitron.models.implicit_function.base import ImplicitFunctionBase\n",
"from pytorch3d.implicitron.models.implicit_function.base import ImplicitFunctionBase, ImplicitronRayBundle\n",
"from pytorch3d.implicitron.models.renderer.base import EvaluationMode\n",
"from pytorch3d.implicitron.tools.config import expand_args_fields, get_default_args, registry, remove_unused_components\n",
"from pytorch3d.renderer import RayBundle\n",
"from pytorch3d.implicitron.tools.config import get_default_args, registry, remove_unused_components\n",
"from pytorch3d.renderer.implicit.renderer import VolumeSampler\n",
"from pytorch3d.structures import Volumes\n",
"from pytorch3d.vis.plotly_vis import plot_batch_individually, plot_scene"
@ -245,17 +244,6 @@
"!wget -P data/cow_mesh https://dl.fbaipublicfiles.com/pytorch3d/data/cow_mesh/cow_texture.png"
]
},
{
"cell_type": "markdown",
"metadata": {
"customInput": null,
"originalKey": "2a976be8-01bf-4a1c-a6e7-61d5d08c3dbd",
"showInput": false
},
"source": [
"If we want to instantiate one of Implicitron's configurable objects, such as `RenderedMeshDatasetMapProvider`, without using the OmegaConf initialisation (get_default_args), we need to call `expand_args_fields` on the class first."
]
},
{
"cell_type": "code",
"execution_count": null,
@ -272,7 +260,6 @@
},
"outputs": [],
"source": [
"expand_args_fields(RenderedMeshDatasetMapProvider)\n",
"cow_provider = RenderedMeshDatasetMapProvider(\n",
" data_file=\"data/cow_mesh/cow.obj\",\n",
" use_point_light=False,\n",
@ -405,7 +392,7 @@
"\n",
" def forward(\n",
" self,\n",
" ray_bundle: RayBundle,\n",
" ray_bundle: ImplicitronRayBundle,\n",
" fun_viewpool=None,\n",
" global_code=None,\n",
" ):\n",
@ -468,7 +455,6 @@
" gm = GenericModel(**cfg)\n",
"else:\n",
" # constructing GenericModel directly\n",
" expand_args_fields(GenericModel)\n",
" gm = GenericModel(\n",
" implicit_function_class_type=\"MyVolumes\",\n",
" render_image_height=output_resolution,\n",

View File

@ -73,10 +73,9 @@ from PIL import Image
from pytorch3d.implicitron.dataset.dataset_base import FrameData
from pytorch3d.implicitron.dataset.rendered_mesh_dataset_map_provider import RenderedMeshDatasetMapProvider
from pytorch3d.implicitron.models.generic_model import GenericModel
from pytorch3d.implicitron.models.implicit_function.base import ImplicitFunctionBase
from pytorch3d.implicitron.models.implicit_function.base import ImplicitFunctionBase, ImplicitronRayBundle
from pytorch3d.implicitron.models.renderer.base import EvaluationMode
from pytorch3d.implicitron.tools.config import expand_args_fields, get_default_args, registry, remove_unused_components
from pytorch3d.renderer import RayBundle
from pytorch3d.implicitron.tools.config import get_default_args, registry, remove_unused_components
from pytorch3d.renderer.implicit.renderer import VolumeSampler
from pytorch3d.structures import Volumes
from pytorch3d.vis.plotly_vis import plot_batch_individually, plot_scene
@ -112,12 +111,9 @@ get_ipython().system('wget -P data/cow_mesh https://dl.fbaipublicfiles.com/pytor
get_ipython().system('wget -P data/cow_mesh https://dl.fbaipublicfiles.com/pytorch3d/data/cow_mesh/cow_texture.png')
# If we want to instantiate one of Implicitron's configurable objects, such as `RenderedMeshDatasetMapProvider`, without using the OmegaConf initialisation (get_default_args), we need to call `expand_args_fields` on the class first.
# In[ ]:
expand_args_fields(RenderedMeshDatasetMapProvider)
cow_provider = RenderedMeshDatasetMapProvider(
data_file="data/cow_mesh/cow.obj",
use_point_light=False,
@ -184,7 +180,7 @@ class MyVolumes(ImplicitFunctionBase, torch.nn.Module):
def forward(
self,
ray_bundle: RayBundle,
ray_bundle: ImplicitronRayBundle,
fun_viewpool=None,
global_code=None,
):
@ -225,7 +221,6 @@ if CONSTRUCT_MODEL_FROM_CONFIG:
gm = GenericModel(**cfg)
else:
# constructing GenericModel directly
expand_args_fields(GenericModel)
gm = GenericModel(
implicit_function_class_type="MyVolumes",
render_image_height=output_resolution,

View File

@ -129,7 +129,7 @@
"## Load the SMPL model\n",
"\n",
"#### Download the SMPL model\n",
"- Go to http://smpl.is.tue.mpg.de/downloads and sign up.\n",
"- Go to https://smpl.is.tue.mpg.de/download.php and sign up.\n",
"- Download SMPL for Python Users and unzip.\n",
"- Copy the file male template file **'models/basicModel_m_lbs_10_207_0_v1.0.0.pkl'** to the data/DensePose/ folder.\n",
" - rename the file to **'smpl_model.pkl'** or rename the string where it's commented below\n",

View File

@ -96,7 +96,7 @@ sys.path.append(os.path.abspath(''))
# ## Load the SMPL model
#
# #### Download the SMPL model
# - Go to http://smpl.is.tue.mpg.de/downloads and sign up.
# - Go to https://smpl.is.tue.mpg.de/download.php and sign up.
# - Download SMPL for Python Users and unzip.
# - Copy the file male template file **'models/basicModel_m_lbs_10_207_0_v1.0.0.pkl'** to the data/DensePose/ folder.
# - rename the file to **'smpl_model.pkl'** or rename the string where it's commented below

View File

@ -384,9 +384,9 @@ Note that we indicate configurable classes using a special base class <code>Conf
<div class="prompt input_prompt">In [ ]:</div>
<div class="inner_cell">
<div class="input_area">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># expand_args_fields must be called on an object before it is instantiated.</span>
<span class="c1"># A warning is raised if this is missed, but it is possible to not notice the warning.</span>
<span class="c1"># It modifies the class like @dataclass</span>
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># The expand_args_fields function modifies the class like @dataclasses.dataclass.</span>
<span class="c1"># If it has not been called on a Configurable object before it has been instantiated, it will</span>
<span class="c1"># be called automatically.</span>
<span class="n">expand_args_fields</span><span class="p">(</span><span class="n">MyConfigurable</span><span class="p">)</span>
<span class="n">my_configurable_instance</span> <span class="o">=</span> <span class="n">MyConfigurable</span><span class="p">(</span><span class="n">a</span><span class="o">=</span><span class="mi">18</span><span class="p">)</span>
<span class="k">assert</span> <span class="n">my_configurable_instance</span><span class="o">.</span><span class="n">d</span> <span class="o">==</span> <span class="mi">16</span>
@ -400,7 +400,7 @@ Note that we indicate configurable classes using a special base class <code>Conf
<div class="prompt input_prompt">In [ ]:</div>
<div class="inner_cell">
<div class="input_area">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># get_default_args calls expand_args_fields automatically</span>
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># get_default_args also calls expand_args_fields automatically</span>
<span class="n">our_structured</span> <span class="o">=</span> <span class="n">get_default_args</span><span class="p">(</span><span class="n">MyConfigurable</span><span class="p">)</span>
<span class="k">assert</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">our_structured</span><span class="p">,</span> <span class="n">DictConfig</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">OmegaConf</span><span class="o">.</span><span class="n">to_yaml</span><span class="p">(</span><span class="n">our_structured</span><span class="p">))</span>
@ -642,8 +642,7 @@ Note in this case it is necessary to call <code>Module.__init__</code> explicitl
<div class="prompt input_prompt">In [ ]:</div>
<div class="inner_cell">
<div class="input_area">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">expand_args_fields</span><span class="p">(</span><span class="n">MyLinear</span><span class="p">)</span>
<span class="n">my_linear</span> <span class="o">=</span> <span class="n">MyLinear</span><span class="p">()</span>
<div class="highlight hl-ipython3"><pre><span></span><span class="n">my_linear</span> <span class="o">=</span> <span class="n">MyLinear</span><span class="p">()</span>
<span class="nb">input</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="n">output</span> <span class="o">=</span> <span class="n">my_linear</span><span class="p">(</span><span class="nb">input</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"output shape:"</span><span class="p">,</span> <span class="n">output</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span>
@ -736,8 +735,7 @@ before you <em>use</em> the library classes.</p>
<div class="prompt input_prompt">In [ ]:</div>
<div class="inner_cell">
<div class="input_area">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">expand_args_fields</span><span class="p">(</span><span class="n">Out</span><span class="p">)</span>
<span class="n">out2</span> <span class="o">=</span> <span class="n">Out</span><span class="p">(</span><span class="n">inner_class_type</span><span class="o">=</span><span class="s2">"UserImplementedInner"</span><span class="p">)</span>
<div class="highlight hl-ipython3"><pre><span></span><span class="n">out2</span> <span class="o">=</span> <span class="n">Out</span><span class="p">(</span><span class="n">inner_class_type</span><span class="o">=</span><span class="s2">"UserImplementedInner"</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">out2</span><span class="o">.</span><span class="n">inner</span><span class="p">)</span>
</pre></div>
</div>
@ -785,8 +783,7 @@ before you <em>use</em> the library classes.</p>
<div class="prompt input_prompt">In [ ]:</div>
<div class="inner_cell">
<div class="input_area">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">expand_args_fields</span><span class="p">(</span><span class="n">LargeComponent</span><span class="p">)</span>
<span class="n">large_component</span> <span class="o">=</span> <span class="n">LargeComponent</span><span class="p">()</span>
<div class="highlight hl-ipython3"><pre><span></span><span class="n">large_component</span> <span class="o">=</span> <span class="n">LargeComponent</span><span class="p">()</span>
<span class="k">assert</span> <span class="n">large_component</span><span class="o">.</span><span class="n">apply</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">==</span> <span class="mi">4</span>
<span class="nb">print</span><span class="p">(</span><span class="n">OmegaConf</span><span class="o">.</span><span class="n">to_yaml</span><span class="p">(</span><span class="n">LargeComponent</span><span class="p">))</span>
</pre></div>
@ -842,8 +839,7 @@ before you <em>use</em> the library classes.</p>
<div class="prompt input_prompt">In [ ]:</div>
<div class="inner_cell">
<div class="input_area">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">expand_args_fields</span><span class="p">(</span><span class="n">LargeComponent</span><span class="p">)</span>
<span class="n">large_component</span> <span class="o">=</span> <span class="n">LargeComponent</span><span class="p">()</span>
<div class="highlight hl-ipython3"><pre><span></span><span class="n">large_component</span> <span class="o">=</span> <span class="n">LargeComponent</span><span class="p">()</span>
<span class="k">assert</span> <span class="n">large_component</span><span class="o">.</span><span class="n">apply</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">==</span> <span class="mi">4</span>
<span class="nb">print</span><span class="p">(</span><span class="n">OmegaConf</span><span class="o">.</span><span class="n">to_yaml</span><span class="p">(</span><span class="n">LargeComponent</span><span class="p">))</span>
</pre></div>
@ -871,7 +867,6 @@ before you <em>use</em> the library classes.</p>
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Appendix:-gotchas-⚠️">Appendix: gotchas ⚠️<a class="anchor-link" href="#Appendix:-gotchas-⚠️"></a></h2><ul>
<li>Omitting to define <code>__post_init__</code> or not calling <code>run_auto_creation</code> in it.</li>
<li>Using a configurable class without calling get_default_args or expand_args_fields on it.</li>
<li>Omitting a type annotation on a field. For example, writing
<pre><code> subcomponent_class_type = "SubComponent"</code></pre>
instead of

View File

@ -384,9 +384,9 @@ Note that we indicate configurable classes using a special base class <code>Conf
<div class="prompt input_prompt">In [ ]:</div>
<div class="inner_cell">
<div class="input_area">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># expand_args_fields must be called on an object before it is instantiated.</span>
<span class="c1"># A warning is raised if this is missed, but it is possible to not notice the warning.</span>
<span class="c1"># It modifies the class like @dataclass</span>
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># The expand_args_fields function modifies the class like @dataclasses.dataclass.</span>
<span class="c1"># If it has not been called on a Configurable object before it has been instantiated, it will</span>
<span class="c1"># be called automatically.</span>
<span class="n">expand_args_fields</span><span class="p">(</span><span class="n">MyConfigurable</span><span class="p">)</span>
<span class="n">my_configurable_instance</span> <span class="o">=</span> <span class="n">MyConfigurable</span><span class="p">(</span><span class="n">a</span><span class="o">=</span><span class="mi">18</span><span class="p">)</span>
<span class="k">assert</span> <span class="n">my_configurable_instance</span><span class="o">.</span><span class="n">d</span> <span class="o">==</span> <span class="mi">16</span>
@ -400,7 +400,7 @@ Note that we indicate configurable classes using a special base class <code>Conf
<div class="prompt input_prompt">In [ ]:</div>
<div class="inner_cell">
<div class="input_area">
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># get_default_args calls expand_args_fields automatically</span>
<div class="highlight hl-ipython3"><pre><span></span><span class="c1"># get_default_args also calls expand_args_fields automatically</span>
<span class="n">our_structured</span> <span class="o">=</span> <span class="n">get_default_args</span><span class="p">(</span><span class="n">MyConfigurable</span><span class="p">)</span>
<span class="k">assert</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">our_structured</span><span class="p">,</span> <span class="n">DictConfig</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">OmegaConf</span><span class="o">.</span><span class="n">to_yaml</span><span class="p">(</span><span class="n">our_structured</span><span class="p">))</span>
@ -642,8 +642,7 @@ Note in this case it is necessary to call <code>Module.__init__</code> explicitl
<div class="prompt input_prompt">In [ ]:</div>
<div class="inner_cell">
<div class="input_area">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">expand_args_fields</span><span class="p">(</span><span class="n">MyLinear</span><span class="p">)</span>
<span class="n">my_linear</span> <span class="o">=</span> <span class="n">MyLinear</span><span class="p">()</span>
<div class="highlight hl-ipython3"><pre><span></span><span class="n">my_linear</span> <span class="o">=</span> <span class="n">MyLinear</span><span class="p">()</span>
<span class="nb">input</span> <span class="o">=</span> <span class="n">torch</span><span class="o">.</span><span class="n">zeros</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="n">output</span> <span class="o">=</span> <span class="n">my_linear</span><span class="p">(</span><span class="nb">input</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"output shape:"</span><span class="p">,</span> <span class="n">output</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span>
@ -736,8 +735,7 @@ before you <em>use</em> the library classes.</p>
<div class="prompt input_prompt">In [ ]:</div>
<div class="inner_cell">
<div class="input_area">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">expand_args_fields</span><span class="p">(</span><span class="n">Out</span><span class="p">)</span>
<span class="n">out2</span> <span class="o">=</span> <span class="n">Out</span><span class="p">(</span><span class="n">inner_class_type</span><span class="o">=</span><span class="s2">"UserImplementedInner"</span><span class="p">)</span>
<div class="highlight hl-ipython3"><pre><span></span><span class="n">out2</span> <span class="o">=</span> <span class="n">Out</span><span class="p">(</span><span class="n">inner_class_type</span><span class="o">=</span><span class="s2">"UserImplementedInner"</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">out2</span><span class="o">.</span><span class="n">inner</span><span class="p">)</span>
</pre></div>
</div>
@ -785,8 +783,7 @@ before you <em>use</em> the library classes.</p>
<div class="prompt input_prompt">In [ ]:</div>
<div class="inner_cell">
<div class="input_area">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">expand_args_fields</span><span class="p">(</span><span class="n">LargeComponent</span><span class="p">)</span>
<span class="n">large_component</span> <span class="o">=</span> <span class="n">LargeComponent</span><span class="p">()</span>
<div class="highlight hl-ipython3"><pre><span></span><span class="n">large_component</span> <span class="o">=</span> <span class="n">LargeComponent</span><span class="p">()</span>
<span class="k">assert</span> <span class="n">large_component</span><span class="o">.</span><span class="n">apply</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">==</span> <span class="mi">4</span>
<span class="nb">print</span><span class="p">(</span><span class="n">OmegaConf</span><span class="o">.</span><span class="n">to_yaml</span><span class="p">(</span><span class="n">LargeComponent</span><span class="p">))</span>
</pre></div>
@ -842,8 +839,7 @@ before you <em>use</em> the library classes.</p>
<div class="prompt input_prompt">In [ ]:</div>
<div class="inner_cell">
<div class="input_area">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">expand_args_fields</span><span class="p">(</span><span class="n">LargeComponent</span><span class="p">)</span>
<span class="n">large_component</span> <span class="o">=</span> <span class="n">LargeComponent</span><span class="p">()</span>
<div class="highlight hl-ipython3"><pre><span></span><span class="n">large_component</span> <span class="o">=</span> <span class="n">LargeComponent</span><span class="p">()</span>
<span class="k">assert</span> <span class="n">large_component</span><span class="o">.</span><span class="n">apply</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">==</span> <span class="mi">4</span>
<span class="nb">print</span><span class="p">(</span><span class="n">OmegaConf</span><span class="o">.</span><span class="n">to_yaml</span><span class="p">(</span><span class="n">LargeComponent</span><span class="p">))</span>
</pre></div>
@ -871,7 +867,6 @@ before you <em>use</em> the library classes.</p>
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Appendix:-gotchas-⚠️">Appendix: gotchas ⚠️<a class="anchor-link" href="#Appendix:-gotchas-⚠️"></a></h2><ul>
<li>Omitting to define <code>__post_init__</code> or not calling <code>run_auto_creation</code> in it.</li>
<li>Using a configurable class without calling get_default_args or expand_args_fields on it.</li>
<li>Omitting a type annotation on a field. For example, writing
<pre><code> subcomponent_class_type = "SubComponent"</code></pre>
instead of

View File

@ -174,10 +174,9 @@
<span class="kn">from</span> <span class="nn">pytorch3d.implicitron.dataset.dataset_base</span> <span class="kn">import</span> <span class="n">FrameData</span>
<span class="kn">from</span> <span class="nn">pytorch3d.implicitron.dataset.rendered_mesh_dataset_map_provider</span> <span class="kn">import</span> <span class="n">RenderedMeshDatasetMapProvider</span>
<span class="kn">from</span> <span class="nn">pytorch3d.implicitron.models.generic_model</span> <span class="kn">import</span> <span class="n">GenericModel</span>
<span class="kn">from</span> <span class="nn">pytorch3d.implicitron.models.implicit_function.base</span> <span class="kn">import</span> <span class="n">ImplicitFunctionBase</span>
<span class="kn">from</span> <span class="nn">pytorch3d.implicitron.models.implicit_function.base</span> <span class="kn">import</span> <span class="n">ImplicitFunctionBase</span><span class="p">,</span> <span class="n">ImplicitronRayBundle</span>
<span class="kn">from</span> <span class="nn">pytorch3d.implicitron.models.renderer.base</span> <span class="kn">import</span> <span class="n">EvaluationMode</span>
<span class="kn">from</span> <span class="nn">pytorch3d.implicitron.tools.config</span> <span class="kn">import</span> <span class="n">expand_args_fields</span><span class="p">,</span> <span class="n">get_default_args</span><span class="p">,</span> <span class="n">registry</span><span class="p">,</span> <span class="n">remove_unused_components</span>
<span class="kn">from</span> <span class="nn">pytorch3d.renderer</span> <span class="kn">import</span> <span class="n">RayBundle</span>
<span class="kn">from</span> <span class="nn">pytorch3d.implicitron.tools.config</span> <span class="kn">import</span> <span class="n">get_default_args</span><span class="p">,</span> <span class="n">registry</span><span class="p">,</span> <span class="n">remove_unused_components</span>
<span class="kn">from</span> <span class="nn">pytorch3d.renderer.implicit.renderer</span> <span class="kn">import</span> <span class="n">VolumeSampler</span>
<span class="kn">from</span> <span class="nn">pytorch3d.structures</span> <span class="kn">import</span> <span class="n">Volumes</span>
<span class="kn">from</span> <span class="nn">pytorch3d.vis.plotly_vis</span> <span class="kn">import</span> <span class="n">plot_batch_individually</span><span class="p">,</span> <span class="n">plot_scene</span>
@ -241,21 +240,12 @@ If running locally, the data is already available at the correct path.</p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>If we want to instantiate one of Implicitron's configurable objects, such as <code>RenderedMeshDatasetMapProvider</code>, without using the OmegaConf initialisation (get_default_args), we need to call <code>expand_args_fields</code> on the class first.</p>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [ ]:</div>
<div class="inner_cell">
<div class="input_area">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">expand_args_fields</span><span class="p">(</span><span class="n">RenderedMeshDatasetMapProvider</span><span class="p">)</span>
<span class="n">cow_provider</span> <span class="o">=</span> <span class="n">RenderedMeshDatasetMapProvider</span><span class="p">(</span>
<div class="highlight hl-ipython3"><pre><span></span><span class="n">cow_provider</span> <span class="o">=</span> <span class="n">RenderedMeshDatasetMapProvider</span><span class="p">(</span>
<span class="n">data_file</span><span class="o">=</span><span class="s2">"data/cow_mesh/cow.obj"</span><span class="p">,</span>
<span class="n">use_point_light</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
<span class="n">resolution</span><span class="o">=</span><span class="n">output_resolution</span><span class="p">,</span>
@ -344,7 +334,7 @@ We use Python's dataclass annotations for configuring the module.</p>
<span class="k">def</span> <span class="nf">forward</span><span class="p">(</span>
<span class="bp">self</span><span class="p">,</span>
<span class="n">ray_bundle</span><span class="p">:</span> <span class="n">RayBundle</span><span class="p">,</span>
<span class="n">ray_bundle</span><span class="p">:</span> <span class="n">ImplicitronRayBundle</span><span class="p">,</span>
<span class="n">fun_viewpool</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">global_code</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="p">):</span>
@ -394,7 +384,6 @@ There are two ways to construct it which are equivalent here.</p>
<span class="n">gm</span> <span class="o">=</span> <span class="n">GenericModel</span><span class="p">(</span><span class="o">**</span><span class="n">cfg</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="c1"># constructing GenericModel directly</span>
<span class="n">expand_args_fields</span><span class="p">(</span><span class="n">GenericModel</span><span class="p">)</span>
<span class="n">gm</span> <span class="o">=</span> <span class="n">GenericModel</span><span class="p">(</span>
<span class="n">implicit_function_class_type</span><span class="o">=</span><span class="s2">"MyVolumes"</span><span class="p">,</span>
<span class="n">render_image_height</span><span class="o">=</span><span class="n">output_resolution</span><span class="p">,</span>

View File

@ -174,10 +174,9 @@
<span class="kn">from</span> <span class="nn">pytorch3d.implicitron.dataset.dataset_base</span> <span class="kn">import</span> <span class="n">FrameData</span>
<span class="kn">from</span> <span class="nn">pytorch3d.implicitron.dataset.rendered_mesh_dataset_map_provider</span> <span class="kn">import</span> <span class="n">RenderedMeshDatasetMapProvider</span>
<span class="kn">from</span> <span class="nn">pytorch3d.implicitron.models.generic_model</span> <span class="kn">import</span> <span class="n">GenericModel</span>
<span class="kn">from</span> <span class="nn">pytorch3d.implicitron.models.implicit_function.base</span> <span class="kn">import</span> <span class="n">ImplicitFunctionBase</span>
<span class="kn">from</span> <span class="nn">pytorch3d.implicitron.models.implicit_function.base</span> <span class="kn">import</span> <span class="n">ImplicitFunctionBase</span><span class="p">,</span> <span class="n">ImplicitronRayBundle</span>
<span class="kn">from</span> <span class="nn">pytorch3d.implicitron.models.renderer.base</span> <span class="kn">import</span> <span class="n">EvaluationMode</span>
<span class="kn">from</span> <span class="nn">pytorch3d.implicitron.tools.config</span> <span class="kn">import</span> <span class="n">expand_args_fields</span><span class="p">,</span> <span class="n">get_default_args</span><span class="p">,</span> <span class="n">registry</span><span class="p">,</span> <span class="n">remove_unused_components</span>
<span class="kn">from</span> <span class="nn">pytorch3d.renderer</span> <span class="kn">import</span> <span class="n">RayBundle</span>
<span class="kn">from</span> <span class="nn">pytorch3d.implicitron.tools.config</span> <span class="kn">import</span> <span class="n">get_default_args</span><span class="p">,</span> <span class="n">registry</span><span class="p">,</span> <span class="n">remove_unused_components</span>
<span class="kn">from</span> <span class="nn">pytorch3d.renderer.implicit.renderer</span> <span class="kn">import</span> <span class="n">VolumeSampler</span>
<span class="kn">from</span> <span class="nn">pytorch3d.structures</span> <span class="kn">import</span> <span class="n">Volumes</span>
<span class="kn">from</span> <span class="nn">pytorch3d.vis.plotly_vis</span> <span class="kn">import</span> <span class="n">plot_batch_individually</span><span class="p">,</span> <span class="n">plot_scene</span>
@ -241,21 +240,12 @@ If running locally, the data is already available at the correct path.</p>
</div>
</div>
</div>
<div class="cell border-box-sizing text_cell rendered"><div class="prompt input_prompt">
</div>
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<p>If we want to instantiate one of Implicitron's configurable objects, such as <code>RenderedMeshDatasetMapProvider</code>, without using the OmegaConf initialisation (get_default_args), we need to call <code>expand_args_fields</code> on the class first.</p>
</div>
</div>
</div>
<div class="cell border-box-sizing code_cell rendered">
<div class="input">
<div class="prompt input_prompt">In [ ]:</div>
<div class="inner_cell">
<div class="input_area">
<div class="highlight hl-ipython3"><pre><span></span><span class="n">expand_args_fields</span><span class="p">(</span><span class="n">RenderedMeshDatasetMapProvider</span><span class="p">)</span>
<span class="n">cow_provider</span> <span class="o">=</span> <span class="n">RenderedMeshDatasetMapProvider</span><span class="p">(</span>
<div class="highlight hl-ipython3"><pre><span></span><span class="n">cow_provider</span> <span class="o">=</span> <span class="n">RenderedMeshDatasetMapProvider</span><span class="p">(</span>
<span class="n">data_file</span><span class="o">=</span><span class="s2">"data/cow_mesh/cow.obj"</span><span class="p">,</span>
<span class="n">use_point_light</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
<span class="n">resolution</span><span class="o">=</span><span class="n">output_resolution</span><span class="p">,</span>
@ -344,7 +334,7 @@ We use Python's dataclass annotations for configuring the module.</p>
<span class="k">def</span> <span class="nf">forward</span><span class="p">(</span>
<span class="bp">self</span><span class="p">,</span>
<span class="n">ray_bundle</span><span class="p">:</span> <span class="n">RayBundle</span><span class="p">,</span>
<span class="n">ray_bundle</span><span class="p">:</span> <span class="n">ImplicitronRayBundle</span><span class="p">,</span>
<span class="n">fun_viewpool</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">global_code</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="p">):</span>
@ -394,7 +384,6 @@ There are two ways to construct it which are equivalent here.</p>
<span class="n">gm</span> <span class="o">=</span> <span class="n">GenericModel</span><span class="p">(</span><span class="o">**</span><span class="n">cfg</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="c1"># constructing GenericModel directly</span>
<span class="n">expand_args_fields</span><span class="p">(</span><span class="n">GenericModel</span><span class="p">)</span>
<span class="n">gm</span> <span class="o">=</span> <span class="n">GenericModel</span><span class="p">(</span>
<span class="n">implicit_function_class_type</span><span class="o">=</span><span class="s2">"MyVolumes"</span><span class="p">,</span>
<span class="n">render_image_height</span><span class="o">=</span><span class="n">output_resolution</span><span class="p">,</span>

View File

@ -204,7 +204,7 @@ In this tutorial, we provide an example of using DensePose data in PyTorch3D.</p
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Load-the-SMPL-model">Load the SMPL model<a class="anchor-link" href="#Load-the-SMPL-model"></a></h2><h4 id="Download-the-SMPL-model">Download the SMPL model<a class="anchor-link" href="#Download-the-SMPL-model"></a></h4><ul>
<li>Go to <a href="http://smpl.is.tue.mpg.de/downloads">http://smpl.is.tue.mpg.de/downloads</a> and sign up.</li>
<li>Go to <a href="https://smpl.is.tue.mpg.de/download.php">https://smpl.is.tue.mpg.de/download.php</a> and sign up.</li>
<li>Download SMPL for Python Users and unzip.</li>
<li>Copy the file male template file <strong>'models/basicModel_m_lbs_10_207_0_v1.0.0.pkl'</strong> to the data/DensePose/ folder.<ul>
<li>rename the file to <strong>'smpl_model.pkl'</strong> or rename the string where it's commented below</li>

View File

@ -204,7 +204,7 @@ In this tutorial, we provide an example of using DensePose data in PyTorch3D.</p
<div class="inner_cell">
<div class="text_cell_render border-box-sizing rendered_html">
<h2 id="Load-the-SMPL-model">Load the SMPL model<a class="anchor-link" href="#Load-the-SMPL-model"></a></h2><h4 id="Download-the-SMPL-model">Download the SMPL model<a class="anchor-link" href="#Download-the-SMPL-model"></a></h4><ul>
<li>Go to <a href="http://smpl.is.tue.mpg.de/downloads">http://smpl.is.tue.mpg.de/downloads</a> and sign up.</li>
<li>Go to <a href="https://smpl.is.tue.mpg.de/download.php">https://smpl.is.tue.mpg.de/download.php</a> and sign up.</li>
<li>Download SMPL for Python Users and unzip.</li>
<li>Copy the file male template file <strong>'models/basicModel_m_lbs_10_207_0_v1.0.0.pkl'</strong> to the data/DensePose/ folder.<ul>
<li>rename the file to <strong>'smpl_model.pkl'</strong> or rename the string where it's commented below</li>