Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add batch normalization for 5d #8268

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Conversation

Riku-KANO
Copy link

@Riku-KANO Riku-KANO commented May 3, 2024

Purpose

For introducing 3D ML models into javascript (#8011).

Implementation detail

Added batchNorm5d module

I implemented following sample code of 3d model in keras. After converting this to JS model and importing it from some files, console outputs need for batch normalizain of rank 5. Thus, I added batchnorm5d.ts following the implementation of other batch normalization code like batchnorm4d.ts.

# keras
class MyNet:
    def __init__(self, height, width, depth, args):
        self.height = height
        self.width = width
        self.depth = depth
        self.args = args
        x_image = create_image()
        h_conv1 = Activation('relu')(BatchNormalization(axis=3)(Conv3D(args.num_channels, 3, padding='same')(x_image)))
        h_conv2 = Activation('relu')(BatchNormalization(axis=3)(Conv3D(args.num_channels, 3, padding='same')(h_conv1)))
        h_conv3 = Activation('relu')(BatchNormalization(axis=3)(Conv3D(args.num_channels, 3, padding='same')(h_conv2)))
        h_conv4 = Activation('relu')(BatchNormalization(axis=3)(Conv3D(args.num_channels, 3, padding='valid')(h_conv3)))
        h_conv4_flat = Flatten()(h_conv4)
        ...
        ...

Updated related codes

In batchnorm.ts, the input tensor reshaped into buffered tensor of rank 4(x4D), exceeding rank 5. I modified the code to be able to handle 5-d batch normalization.

Added test code of batchNorm5d.

Also added test code in batchnorm_test.ts. This code also heavily follows other test code implementation like batchnorm4d.

Note

I created this code with 4.x_dev branch and merged it to local master branch. There must be no conflict.

Copy link

google-cla bot commented May 3, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants