src.tests.spconv3d_pwise_classif_save_load_test
Classes
- class src.tests.spconv3d_pwise_classif_save_load_test.SpConv3DPwiseClassifSaveLoadTest
- Author:
Alberto M. Esmoris Pena
State-dict round-trip test for
SpConv3DPwiseClassif.The architecture has a recurring class of bugs where a constructor kwarg is read from
kwargsbut not persisted to__getstate__/__setstate__— the reload path thenAttributeError``s on the first ``build_output/_build_encoder_hierarchycall (missing ssc3d-specific keys infrom_config; uninitialisedpostwrap_kernel_reswhen the build flag is skipped; missinglayer_by_layer/spconvs_per_encoder/binary_crossentropydefaults).This test exercises the full
__getstate__→__setstate__cycle on three configurations to gate the entire bug class. Each subtest:Builds an architecture instance with non-default settings.
Calls
__getstate__to serialise the configuration.Builds a fresh instance with the same kwargs (so it has all attributes initialised), and calls
__setstate__(state).Verifies the restored instance still has every attribute the
build_*methods need.
Configurations covered:
residual_strategy="sharedmlp"(production smoke default).residual_strategy="ssc3d"(residual-via-spconv path).residual_strategy=None(no-residual fallback path).
- REQUIRED_ATTRS = ('layer_by_layer', 'spconvs_per_encoder', 'binary_crossentropy', 'fnames', 'nf', 'num_classes', 'submanifold_window', 'submanifold_features', 'downsampling_window', 'upsampling_window', 'max_depth', 'residual_strategy', 'feature_dim_divisor', 'dim_transform_activation')
- __init__()
Basic configuration for any VL3D test.
- Parameters:
name (str) – Test name
- run()
Run the test.
- Returns:
True if test is successfully passed, False otherwise.
- Return type:
bool
Round-trip the production-smoke configuration.
- subtest_round_trip_ssc3d()
Round-trip the residual-via-spconv (ssc3d) path.
- subtest_round_trip_no_residual()
Round-trip the no-residual fallback.
- subtest_keras_save_load_real_graph()
Build a real Keras model, save it to disk, reload it via
DL_CUSTOM_OBJECTS, and verify that:load_modeldoes not raise “Could not locate class” for any of the custom SpConv layers (i.e., every layer name is inDL_CUSTOM_OBJECTSor globally registered via@register_keras_serializable);the loaded model and the source model produce the same forward outputs on a tiny dummy batch (the full
model.save → keras.models.load_modelround-trip — including the encoder / decoderfrom_configpaths — is correct).
The field-level round-trip subtests above stub
arch.buildto a no-op, so they never exercise the Keras-side reload path; this subtest is the one that does.
- subtest_refuses_loss_class_mismatch_after_build()
Post-build
overwrite_compilation_argswith a loss whosebinary_crossentropyflag differs from the built head must raiseDeepLearningException.
- subtest_kwargs_mutation_before_build_caught()
Mutating
arch.compilation_argsBEFOREbuild()must update the output head size at build time (the live re-derive inbuild_output()picks up the new flag).
- subtest_missing_fields_default()
Older state dicts may not persist
layer_by_layer,spconvs_per_encoder, orbinary_crossentropy;__setstate__()must default-fill these so the checkpoint still loads. Simulated by emitting a state and deleting the three keys before re-applying.