convrfm

Implements convolutional neural feature ansatz verification and deep ConvRFM training with PyTorch.

75|7|Updated May 2, 2026
One-click install
npx skills add https://github.com/zjunlp/Mechanist --skill convrfm-zjunlp
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: convrfm
Source: https://github.com/zjunlp/Mechanist/tree/main/skills/mechanism-skills/neural-feature-learning/network-as-filter-nfm
Command: npx skills add https://github.com/zjunlp/Mechanist --skill convrfm-zjunlp

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires torch, torchvision, numpy, scipy, h5py, and includes scripts (resource) components.

What problem does it solve? Researchers studying feature learning in convolutional neural networks need reproducible tooling to verify the convolutional neural feature ansatz (CNFA), compute expected gradient outer products (EGOP), and train deep convolutional recursive feature machines, which otherwise requires writing patch-based Jacobian and kernel analysis code from scratch. ## Core Features & Use Cases - CNFA Verification: Compute patch-level Jacobians and EGOP matrices on pretrained ResNet and VGG networks to test whether learned kernels match the neural feature ansatz. - Deep ConvRFM Training: Iteratively train convolutional recursive feature machines with gradient-based kernel updates for binary and multiclass image classification. - Kernel Visualization: Compute and visualize VGG kernel eigenvectors and propagate them through network layers for interpretability analysis. - Use Case: A researcher investigating feature learning on CIFAR or ImageNet can patchify inputs, compute EGOP over a trained VGG network, and compare the resulting feature matrix against the learned convolutional kernels. ## Quick Start Clone the convrfm repository, install PyTorch and its dependencies, then run the EGOP and patchify demo script to compute an expected gradient outer product on synthetic image data.

Frequently Asked Questions about convrfm

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I compute EGOP for a convolutional neural network?

Use the egop function from the convrfm repository, which computes the expected gradient outer product by averaging Jacobian outer products over a dataset. Patchify inputs first with patchify(x, patch_size, stride_size), then pass the model and data to egop in mini-batches to avoid memory overflow.

How do I train a deep convolutional recursive feature machine?

Run main.py inside the deep_conv_rfm directory for multiclass tasks or binary_main.py for two-class problems. The training loop iteratively refines feature representations through gradient-based kernel updates on image datasets.

Does convrfm support pretrained ResNet and VGG networks?

Yes, the cnfa_verification module provides PatchConvLayer, PatchBasicBlock, and PatchBottleneck wrappers for pretrained ResNet and VGG networks. These enable patch-based Jacobian and EGOP computation on standard torchvision architectures.

Why does Jacobian computation fail with no gradient error?

Jacobian computation requires gradient tracking, so torch.no_grad() must not be active and the input tensor must have requires_grad set to True. Keep the model in eval mode but ensure gradients flow through the patchified input data.

Can I test the convrfm pipeline without ImageNet?

Yes, run gen_toy_data.py to generate synthetic datasets for quick experimentation and debugging. The demo script also runs standalone with random tensors, so you can validate patchify, Jacobian, and EGOP logic before scaling to real datasets.