{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# How to compute descriptors from Features extractors?" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from geomfum.dataset import NotebooksDataset\n", "from geomfum.descriptor.learned import FeatureExtractor, LearnedDescriptor\n", "from geomfum.shape import TriangleMesh\n", "import torch" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[Load a mesh](00_load_mesh_from_file.ipynb)." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "INFO: Data has already been downloaded... using cached file ('/home/ubuntu/.geomfum/data/cat-00.off').\n", "/home/ubuntu/giulio_vigano/geomfum_proj/venv/lib/python3.12/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n" ] } ], "source": [ "dataset = NotebooksDataset()\n", "mesh = TriangleMesh.from_file(dataset.get_filename(\"cat-00\"))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[Set Laplace eigenbasis](./02_mesh_laplacian_spectrum.ipynb)." ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mesh.laplacian.find_spectrum(spectrum_size=10, set_as_basis=True)\n", "\n", "mesh.basis" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## DiffusionNet" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(128, 7207)" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "descr = LearnedDescriptor(\n", " feature_extractor=FeatureExtractor.from_registry(which=\"diffusionnet\")\n", ")\n", "with torch.no_grad():\n", " hsign = descr(mesh)\n", "\n", "hsign = hsign\n", "\n", "hsign.shape" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# PointNet" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(128, 7207)" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "descr = LearnedDescriptor(\n", " feature_extractor=FeatureExtractor.from_registry(which=\"pointnet\")\n", ")\n", "with torch.no_grad():\n", " hsign = descr(mesh)\n", "\n", "hsign = hsign\n", "\n", "hsign.shape" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Descriptors as input" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(128, 7207)" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from geomfum.descriptor.spectral import HeatKernelSignature\n", "\n", "descr = LearnedDescriptor(\n", " feature_extractor=FeatureExtractor.from_registry(\n", " which=\"diffusionnet\",\n", " descriptor=HeatKernelSignature(n_domain=128),\n", " in_channels=128,\n", " )\n", ")\n", "with torch.no_grad():\n", " hsign = descr(mesh)\n", "\n", "hsign = hsign\n", "\n", "hsign.shape" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Pipeline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can use learned features also concatenated with other descriptors in the pipeline" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "from geomfum.descriptor.pipeline import (\n", " DescriptorPipeline,\n", ")\n", "from geomfum.descriptor.spectral import HeatKernelSignature\n", "from geomfum.descriptor.spectral import HeatKernelSignature\n", "from geomfum.shape import TriangleMesh" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(132, 7207)" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "steps = [\n", " HeatKernelSignature(n_domain=4),\n", " descr,\n", "]\n", "\n", "pipeline = DescriptorPipeline(steps)\n", "\n", "hsign = pipeline.apply(mesh)\n", "hsign.shape\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Saving and loading\n" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "descr = LearnedDescriptor()\n", "\n", "descr.feature_extractor.save(\"./saved_model_test.pth\")" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "descr2 = LearnedDescriptor()\n", "descr2.feature_extractor.load_from_path(\"./saved_model_test.pth\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Further reading\n", "\n", "* [How to compute a functional map?](./07_functional_map.ipynb)\n", "\n", "* [How to set landmarks?](./06_landmarks.ipynb)" ] } ], "metadata": { "kernelspec": { "display_name": "venv", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.3" } }, "nbformat": 4, "nbformat_minor": 2 }