Refining sakuro's solution to fix deep_transform in #10887.