This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.conf.urls import include | |
| from django.urls import path | |
| from rest_framework import routers | |
| from .views import InferenceViewSet | |
| router = routers.DefaultRouter() | |
| router.register('inference', InferenceViewSet) | |
| urlpatterns = [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from rest_framework.decorators import action | |
| from rest_framework.response import Response | |
| from rest_framework import viewsets,status,generics | |
| from .serializers import InferenceSerializer | |
| from .models import Inference | |
| from celery.result import AsyncResult | |
| class InferenceViewSet(viewsets.ModelViewSet): | |
| serializer_class = InferenceSerializer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from rest_framework import serializers | |
| from .models import Inference | |
| from .tasks import run_inference | |
| class InferenceSerializers(serializers.ModelSerializers): | |
| class Meta : | |
| model = Inference | |
| fields = ('name','result') | |
| def create(self,validated_data): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django.db import models | |
| class Inference(models.Model): | |
| name = models.CharField(max_length=255) | |
| result = models.CharField(max_length=255) | |
| def __str__(self): | |
| return '{name} => result : {result}'.format(name=self.name,result=self.result) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| FROM python:3.6 # base image | |
| RUN mkdir src # create a src directory | |
| WORKDIR /src # change directory to src | |
| ADD . /src/ # add the django code to src | |
| RUN pip install requirements.txt # install the python library |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def predict(x,w1,w2,w3,b1,b2,b3) : | |
| l1 = sigmoid(np.dot(x,w1) + b1) | |
| l2 = sigmoid(np.dot(l1,w2) + b2) | |
| l3 = sigmoid(np.dot(l2,w3) + b3) | |
| print(l3.round(decimals=2)) | |
| test = x[0] | |
| predict(test,*params) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| params = w1,w2,w3,b1,b2,b3 | |
| for i in range(0,10000) : | |
| params = train(x,y,*params) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def train(x,y,w1,w2,w3,b1,b2,b3) : | |
| # feed forward | |
| inp_l = x | |
| l1 = sigmoid(np.dot(inp_l,w1) + b1) | |
| l2 = sigmoid(np.dot(l1,w2) + b2) | |
| l3 = sigmoid(np.dot(l2,w3) + b3) | |
| #backpropagation | |
| delta_l3 = (y - l3)*sigmoid_prime(l3) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def sigmoid_prime(x): | |
| return x*(1-x) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def sigmoid(x): | |
| return 1/(1+np.exp(-x)) |