E
E
Enta2019-05-29 21:04:41
Python
Enta, 2019-05-29 21:04:41

How to use a neural network in an application?

Using the guides, I got a neural network in PyTorch that suits me.
Question

how to use it?
:
you need something like a java function that pulls something and produces a result
, maybe there is an example or an article on this topic, I just couldn’t come up with a correct search query , ideally , the network itself would be very simple
without python at all :
class Net(nn.Module):
   def __init__(self):
       super(Net, self).__init__()
       self.fc1 = nn.Linear(276, 276)
       self.fc2 = nn.Linear(276, 276)
       self.fc3 = nn.Linear(276, 109)

   def forward(self, x):
        x = F.relu(self.fc1(x))
        x = F.relu(self.fc2(x))
        x = self.fc3(x)
        return F.log_softmax(x)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Danil, 2019-05-30
@Enta

There are several approaches:

  1. You create a Python script that will load the saved model and make predictions. And from java run this python script.
    Of the shortcomings - it works slowly. Each time, all Python libraries are initialized and the model itself is loaded. Suitable when you rarely make predictions on any batch.
  2. You use Flask, for example, and create a REST API that makes predictions using a stored model.
    Of the shortcomings , you need to host a separate service.

K
kova1ev, 2019-05-29
@kova1ev

I won’t say about pytorch, I didn’t use it, but in other frameworks you can save the trained model, I’m sure that it’s also possible in pytorch.
That is, you first need to train your network, save it, then simply load this model in your application and make a prediction on the necessary data, give the result somewhere further into the application.
upd googled it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question