• Y
  • List All
  • Feedback
    • This Project
    • All Projects
Profile Account settings Log out
  • Favorite
  • Project
  • All
Loading...
  • Log in
  • Sign up
yjyoon / Altron_Backend star
  • Project homeH
  • CodeC
  • IssueI
  • Pull requestP
  • Review R
  • MilestoneM
  • BoardB
  • Files
  • Commit
  • Branches
Altron_Backendaction.py
Download as .zip file
File name
Commit message
Commit date
asset
made ai analysis api and tested it. 25TPS using gunicorn app:app -w 12 -b 127.0.0.1:8080
2023-10-24
database
added gps querying function
2023-10-30
model
made ai analysis api and tested it. 25TPS using gunicorn app:app -w 12 -b 127.0.0.1:8080
2023-10-24
subfuction
made ai analysis api and tested it. 25TPS using gunicorn app:app -w 12 -b 127.0.0.1:8080
2023-10-24
weights
Hello Yona
2023-08-21
README.md
Hello Yona
2023-08-21
action.py
CORS
2023-10-31
app.py
CORS
2023-10-31
auth.py
made ai analysis api and tested it. 25TPS using gunicorn app:app -w 12 -b 127.0.0.1:8080
2023-10-24
demonstration.py
made ai analysis api and tested it. 25TPS using gunicorn app:app -w 12 -b 127.0.0.1:8080
2023-10-24
yjyoon 2023-10-31 54e15d6 CORS UNIX
Raw Open in browser Change history
from flask_restx import Resource, Namespace from flask import request, jsonify import os import json from database.database import DB import torch from torchvision.transforms import ToTensor from model.AttentiveRNN import AttentiveRNN from model.Classifier import Resnet as Classifier from subfuction.image_crop import crop_image import numpy as np import cv2 db = DB() device = torch.device('cuda' if torch.cuda.is_available() else 'cpu') # pre-loading models arnn = AttentiveRNN(6, 3, 2) arnn.eval() arnn.load_state_dict(torch.load("weights/ARNN_trained_weight_6_3_2.pt")) arnn.to(device=device) classifier = Classifier() classifier.eval() classifier.load_state_dict(torch.load("weights/Classifier_512.pt")) classifier.to(device=device) tf_toTensor = ToTensor() crop_size = (512, 512) start_point = (750, 450) root_dir = os.getcwd() Action = Namespace( name="Action", description="노드 분석을 위해 사용하는 api.", ) @Action.route('/image_anal') class fileUpload(Resource): @Action.doc(responses={200: 'Success'}) @Action.doc(responses={500: 'Register Failed'}) def post(self): uploaded_file = request.files.get('file') if not uploaded_file: return {"message": "No file uploaded"}, 400 json_data = request.form.get('data') if not json_data: return {"message": "Missing JSON data"}, 400 data = json.loads(json_data) lat = float(data['gps_x']) lon = float(data['gps_y']) # filename = data['filename'] # file_type = data['file_type'] uploaded_file = request.files.get('file') file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8) image = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR) image = crop_image(image, crop_size, start_point) image_tensor = tf_toTensor(image) image_tensor = image_tensor.unsqueeze(0) image_tensor = image_tensor.to(device) with torch.no_grad(): image_arnn = arnn(image_tensor) image_tensor.cpu() del image_tensor result = classifier(image_arnn['x']) image_arnn['x'].cpu() del image_arnn result = result.to("cpu") _, predicted = torch.max(result.data, 1) del result if predicted == 0: rain = False else: # elif result == 1 rain = True user_id = 'test' action_success = True action_id = 'test' db.db_add_action(action_id, lat, lon, user_id, action_success) return { 'node': (lat, lon), 'rain': rain, }, 200 @Action.route('/action_display') class fileUpload(Resource): @Action.doc(responses={200: 'Success'}) @Action.doc(responses={500: 'Register Failed'}) def get(self): if request.method == 'GET': db = DB() value = db.db_display_action() return { 'report': list(value) }, 200

          
        
    
    
Copyright Yona authors & © NAVER Corp. & NAVER LABS Supported by NAVER CLOUD PLATFORM

or
Sign in with github login with Google Sign in with Google
Reset password | Sign up