cvxpy icon indicating copy to clipboard operation
cvxpy copied to clipboard

Can Variable be converted to Tensor

Open fine4303 opened this issue 2 years ago • 3 comments

Hello, I'm a newbie in Machine Learning. I constructe a neural network using torch and I want Variable serve as neural network inputs.

my code:

model = nn.gen_nn()
model.load_state_dict(torch.load('NN.pt'), strict=True)

p = cvxpy.Variable(n)
V = model(p)
objective = cvxpy.Maximize(V)
constraints = []
prob = cvxpy.Problem(objective, constraints)

the issue is that Variable cannot convert to Tensor. Is my idea feasible? Any help is great! thanks!

fine4303 avatar Nov 07 '23 04:11 fine4303

Unfortunately this isn't supported at the moment. There is no Intermediate Representation between cvxpy and torch currently, but it is something that the developers are planning to add soon.

Transurgeon avatar Nov 07 '23 19:11 Transurgeon

Unfortunately this isn't supported at the moment. There is no Intermediate Representation between cvxpy and torch currently, but it is something that the developers are planning to add soon.

Thank you very much for your answer! To the best of your knowledge, can you tell me what tools can solve the maximum/minimum value of a neural network?

fine4303 avatar Nov 08 '23 01:11 fine4303

I am not too familiar with Neural Networks, sorry about that. I would look deeper into torch features, it is possible that something similar exists. With some little searching I found that the cost-functions of neural networks are generally not convex (see here). Maybe you could look into cvxpylayers?

Transurgeon avatar Nov 09 '23 17:11 Transurgeon