Giter Club home page Giter Club logo

mionet's People

Contributors

jpzxshi avatar lululxvi avatar shuaimeng0601 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

mionet's Issues

Predict from restored model

Hi @lululxvi , @ShuaiMeng0601 and @jpzxshi.

Thank you for such a great work. I was looking for a version of PINN model and went through your multiple articles and decided to use MIONet since I need to use more than one 'u'. I could generate the data and train the model and save it in my local repository. I could also successfully restore the saved model.

At this stage, I am trying to predict with the test data that was generated in the step 1 using the restored model.

However, I am facing issue with using this model with new data. I looked at the FAQ of DeepXDE and issues in DeepONet and could not find the fix/solution.

Please find the code and the error below. Looking forward for your reply.

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import itertools

import numpy as np
from deepxde.backend import tf
import os
from scipy.integrate import solve_ivp
import deepxde as dde
from spaces import FinitePowerSeries, FiniteChebyshev, GRF
from utils import merge_values, trim_to_65535, mean_squared_error_outlier, safe_test

from deepxde.nn.tensorflow_compat_v1.mionet import MIONetCartesianProd
from deepxde.data.quadruple import QuadrupleCartesianProd

def int_index(x, t, T):
    mat = np.linspace(0, T, x)
    return int(t / mat[1])

def ode(m, T, sensor_values1, sensor_values2):
    """ODE system"""
    s0 = [0, 0]  # initial condition

    def model(t, s):
        k = 1
        u1 = lambda t: sensor_values1[t]
        u2 = lambda t: sensor_values2[t]
        return [
            s[1] + u1(int_index(m, t, T)),
            -k * np.sin(s[0]) + u2(int_index(m, t, T)),
        ]

    res = solve_ivp(model, [0, T], s0, method="RK45", t_eval=np.linspace(0, T, m), vectorized = True)
    return res.y[0, :], res.y[1, :]

def network(problem, m):
    if problem == "ODE":
        branch = [m, 200, 200]
        trunk = [1, 200, 200]
    elif problem == "DR":
        branch = [m, 200, 200]
        trunk = [2, 200, 200]
    elif problem == "ADVD":
        branch = [m, 300, 300, 300]
        trunk = [2, 300, 300, 300]
    return branch, trunk

problem = "ODE"
T = 1
m = 100
lr = 0.0002 if problem in ["ADVD"] else 0.001
epochs = 100000
activation = (
    ["relu", None, "relu"] if problem in ["ADVD"] else ["relu", "relu", "relu"]
)
initializer = "Glorot normal"

training_data = np.load("../data/" + problem + "_train_1.npz", allow_pickle=True)
testing_data = np.load("../data/" + problem + "_test_1.npz", allow_pickle=True)

X_train = training_data["X_train"]
y_train = training_data["y_train"]
X_test = testing_data["X_test"]
y_test = testing_data["y_test"]


branch_net, trunk_net = network(problem, m)

data = QuadrupleCartesianProd(X_train, y_train, X_test, y_test)

net = MIONetCartesianProd(
    branch_net,
    branch_net,
    trunk_net,
    {"branch1": activation[0], "branch2": activation[1], "trunk": activation[2]},
    initializer,
    regularization=None,
)

model = dde.Model(data, net)
model.compile("adam", lr=lr)
checker = dde.callbacks.ModelCheckpoint(
    "model/mionet_model", save_better_only=True, period=1000
)

model.restore(os.path.normpath("model/mionet_model-96000.ckpt"), verbose=1)

model.predict(X_test)

I get the below error when I predict with the X_test which was the same data that was used while training the model.

image

calculate parameters

print(
"# Parameters:",
np.sum(
[
np.prod(v.get_shape().as_list())
for v in tf.compat.v1.trainable_variables()
]
)
If I use pytorch as backend, how can I modify this part of code to calculate parameters

Expand to situations with more than 2 inputs.

Hi,

I noted that in your code, it is suitable for 2 input situations, if I want to extend it to 3D or even more situations.

Which part of your code should I modify?

Regards,
Peng

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.