Yoonjunhyeon

백엔드 내에서 스크립트 실행 성공

Showing 75 changed files with 189 additions and 102 deletions
......@@ -18,9 +18,9 @@ MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
def file_upload_path( filename):
ext = filename.split('.')[-1]
d = datetime.datetime.now()
filepath = d.strftime('%Y\\%m\\%d')
filepath = d.strftime('%Y-%m-%d')
suffix = d.strftime("%Y%m%d%H%M%S")
filename = "%s_%s.%s"%(uuid.uuid4().hex, suffix, ext)
filename = "%s.%s"%(suffix, ext)
return os.path.join( MEDIA_ROOT , filepath, filename)
# DB 필드에서 호출
......
......@@ -12,6 +12,8 @@ from django.shortcuts import get_object_or_404, render
from api.models import Video, VideoFile
from api.serializers import VideoSerializer, VideoFileSerializer
from api import file_upload_path
import subprocess
import shlex
# Create your views here.
......@@ -22,6 +24,9 @@ class VideoViewSet(viewsets.ModelViewSet):
queryset = Video.objects.all()
serializer_class = VideoSerializer
class VideoFileViewSet(viewsets.ModelViewSet):
queryset = VideoFile.objects.all()
......@@ -37,18 +42,19 @@ class VideoFileUploadView(APIView):
return Response(serializer.data)
def post(self, req, *args, **kwargs):
# 동영상 길이
runTime = 126
# 요청된 데이터를 꺼냄( QueryDict)
new_data = req.data.dict()
# 요청된 파일 객체
print(req.data)
file_name = req.data['file']
# 저장될 파일의 풀path를 생성
new_file_full_name = file_upload_path(file_name.name)
print(new_file_full_name)
# 새롭게 생성된 파일의 경로
file_path = '\\'.join(new_file_full_name.split('\\')[0:-1])
file_path = '-'.join(new_file_full_name.split('-')[0:-1])
new_data['file_path'] = file_path
new_data['file_origin_name'] = req.data['file'].name
......@@ -56,12 +62,15 @@ class VideoFileUploadView(APIView):
new_query_dict = QueryDict('', mutable=True)
new_query_dict.update(new_data)
file_serializer = VideoFileSerializer(data = new_query_dict)
if file_serializer.is_valid():
file_serializer.save()
print(file_serializer.data)
process = subprocess.Popen(['./runMediaPipe.sh %s %s' %(file_serializer.data['file_save_name'],runTime,)], shell = True)
process.wait()
return Response(True, status=status.HTTP_201_CREATED)
else:
return Response(file_serializer.errors, status=status.HTTP_400_BAD_REQUEST)
......
import tensorflow as tf
import glob, os
import numpy
def _make_bytes(int_array):
if bytes == str: # Python2
return ''.join(map(chr, int_array))
else:
return bytes(int_array)
def quantize(features, min_quantized_value=-2.0, max_quantized_value=2.0):
"""Quantizes float32 `features` into string."""
assert features.dtype == 'float32'
assert len(features.shape) == 1 # 1-D array
features = numpy.clip(features, min_quantized_value, max_quantized_value)
quantize_range = max_quantized_value - min_quantized_value
features = (features - min_quantized_value) * (255.0 / quantize_range)
features = [int(round(f)) for f in features]
return _make_bytes(features)
# for parse feature.pb
contexts = {
'AUDIO/feature/dimensions': tf.io.FixedLenFeature([], tf.int64),
'AUDIO/feature/rate': tf.io.FixedLenFeature([], tf.float32),
'RGB/feature/dimensions': tf.io.FixedLenFeature([], tf.int64),
'RGB/feature/rate': tf.io.FixedLenFeature([], tf.float32),
'clip/data_path': tf.io.FixedLenFeature([], tf.string),
'clip/end/timestamp': tf.io.FixedLenFeature([], tf.int64),
'clip/start/timestamp': tf.io.FixedLenFeature([], tf.int64)
}
features = {
'AUDIO/feature/floats': tf.io.VarLenFeature(dtype=tf.float32),
'AUDIO/feature/timestamp': tf.io.VarLenFeature(tf.int64),
'RGB/feature/floats': tf.io.VarLenFeature(dtype=tf.float32),
'RGB/feature/timestamp': tf.io.VarLenFeature(tf.int64)
}
def parse_exmp(serial_exmp):
_, sequence_parsed = tf.io.parse_single_sequence_example(
serialized=serial_exmp,
context_features=contexts,
sequence_features=features)
sequence_parsed = tf.contrib.learn.run_n(sequence_parsed)[0]
audio = sequence_parsed['AUDIO/feature/floats'].values
rgb = sequence_parsed['RGB/feature/floats'].values
# print(audio.values)
# print(type(audio.values))
# audio is 128 8bit, rgb is 1024 8bit for every second
audio_slices = [audio[128 * i: 128 * (i + 1)] for i in range(len(audio) // 128)]
rgb_slices = [rgb[1024 * i: 1024 * (i + 1)] for i in range(len(rgb) // 1024)]
byte_audio = []
byte_rgb = []
for seg in audio_slices:
audio_seg = quantize(seg)
byte_audio.append(audio_seg)
for seg in rgb_slices:
rgb_seg = quantize(seg)
byte_rgb.append(rgb_seg)
return byte_audio, byte_rgb
def make_exmp(id, labels, audio, rgb):
audio_features = []
rgb_features = []
for embedding in audio:
embedding_feature = tf.train.Feature(
bytes_list=tf.train.BytesList(value=[embedding]))
audio_features.append(embedding_feature)
for embedding in rgb:
embedding_feature = tf.train.Feature(
bytes_list=tf.train.BytesList(value=[embedding]))
rgb_features.append(embedding_feature)
# for construct yt8m data
seq_exmp = tf.train.SequenceExample(
context=tf.train.Features(
feature={
'id': tf.train.Feature(bytes_list=tf.train.BytesList(
value=[id.encode('utf-8')])),
'labels': tf.train.Feature(int64_list=tf.train.Int64List(
value=[labels]))
}),
feature_lists=tf.train.FeatureLists(
feature_list={
'audio': tf.train.FeatureList(
feature=audio_features
),
'rgb': tf.train.FeatureList(
feature=rgb_features
)
})
)
serialized = seq_exmp.SerializeToString()
return serialized
if __name__ == '__main__':
filename = '/tmp/mediapipe/features.pb'
sequence_example = open(filename, 'rb').read()
audio, rgb = parse_exmp(sequence_example)
id = 'test_001'
labels = 1
tmp_example = make_exmp(id, labels, audio, rgb)
decoded = tf.train.SequenceExample.FromString(tmp_example)
print(decoded)
# then you can write tmp_example to tfrecord files
\ No newline at end of file
......@@ -28,7 +28,7 @@ deactivate () {
fi
unset VIRTUAL_ENV
if [ ! "$1" = "nondestructive" ] ; then
if [ ! "${1:-}" = "nondestructive" ] ; then
# Self destruct!
unset -f deactivate
fi
......@@ -37,7 +37,7 @@ deactivate () {
# unset irrelevant variables
deactivate nondestructive
VIRTUAL_ENV="/home/jun/documents/Univ/PKH_Project1/web/backend/env"
VIRTUAL_ENV="/home/jun/documents/univ/PKH_Project1/web/backend/env"
export VIRTUAL_ENV
_OLD_VIRTUAL_PATH="$PATH"
......
......@@ -8,7 +8,7 @@ alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PA
# Unset irrelevant variables.
deactivate nondestructive
setenv VIRTUAL_ENV "/home/jun/documents/Univ/PKH_Project1/web/backend/env"
setenv VIRTUAL_ENV "/home/jun/documents/univ/PKH_Project1/web/backend/env"
set _OLD_VIRTUAL_PATH="$PATH"
setenv PATH "$VIRTUAL_ENV/bin:$PATH"
......
......@@ -29,7 +29,7 @@ end
# unset irrelevant variables
deactivate nondestructive
set -gx VIRTUAL_ENV "/home/jun/documents/Univ/PKH_Project1/web/backend/env"
set -gx VIRTUAL_ENV "/home/jun/documents/univ/PKH_Project1/web/backend/env"
set -gx _OLD_VIRTUAL_PATH $PATH
set -gx PATH "$VIRTUAL_ENV/bin" $PATH
......@@ -52,7 +52,7 @@ if test -z "$VIRTUAL_ENV_DISABLE_PROMPT"
set -l old_status $status
# Prompt override?
if test -n "(env) "
if test -n "(env) "
printf "%s%s" "(env) " (set_color normal)
else
# ...Otherwise, prepend env
......
#!/home/jun/documents/Univ/PKH_Project1/web/backend/env/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from autopep8 import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(main())
#!/home/jun/documents/Univ/PKH_Project1/web/backend/env/bin/python
#!/home/jun/documents/univ/PKH_Project1/web/backend/env/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from django.core.management import execute_from_command_line
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(execute_from_command_line())
......
#!/home/jun/documents/Univ/PKH_Project1/web/backend/env/bin/python
#!/home/jun/documents/univ/PKH_Project1/web/backend/env/bin/python
from django.core import management
if __name__ == "__main__":
......
#!/home/jun/documents/Univ/PKH_Project1/web/backend/env/bin/python
#!/home/jun/documents/univ/PKH_Project1/web/backend/env/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from setuptools.command.easy_install import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
......
#!/home/jun/documents/Univ/PKH_Project1/web/backend/env/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from setuptools.command.easy_install import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(main())
#!/home/jun/documents/Univ/PKH_Project1/web/backend/env/bin/python
#!/home/jun/documents/univ/PKH_Project1/web/backend/env/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from pip import main
from pip._internal.cli.main import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
......
#!/home/jun/documents/Univ/PKH_Project1/web/backend/env/bin/python
#!/home/jun/documents/univ/PKH_Project1/web/backend/env/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from pip import main
from pip._internal.cli.main import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
......
#!/home/jun/documents/Univ/PKH_Project1/web/backend/env/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from pip import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(main())
#!/home/jun/documents/Univ/PKH_Project1/web/backend/env/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from pycodestyle import _main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(_main())
#!/home/jun/documents/Univ/PKH_Project1/web/backend/env/bin/python
#!/home/jun/documents/univ/PKH_Project1/web/backend/env/bin/python
# -*- coding: utf-8 -*-
import re
import sys
from sqlparse.__main__ import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(main())
......
home = /usr/bin
include-system-site-packages = false
version = 3.6.9
version = 3.8.2
......
#!/bin/bash
cd ../../../mediapipe
. venv/bin/activate
/usr/local/bazel/2.0.0/lib/bazel/bin/bazel version && \
alias bazel='/usr/local/bazel/2.0.0/lib/bazel/bin/bazel'
python -m mediapipe.examples.desktop.youtube8m.generate_input_sequence_example \
--path_to_input_video=/$1 \
--clip_end_time_sec=$2
GLOG_logtostderr=1 bazel-bin/mediapipe/examples/desktop/youtube8m/extract_yt8m_features \
--calculator_graph_config_file=mediapipe/graphs/youtube8m/feature_extraction.pbtxt \
--input_side_packets=input_sequence_example=/tmp/mediapipe/metadata.pb \
--output_side_packets=output_sequence_example=/tmp/mediapipe/features.pb
python convertPb2Tfrecord.py
\ No newline at end of file
#!/bin/bash
. env/bin/activate
pip3 install -r requirements.txt
rm -rf static
./manage.py collectstatic
rm -rf static/admin
rm -rf static/rest_framework
python manage.py makemigrations
python manage.py migrate
python vue2djangoTemplate.py
python manage.py runserver 0.0.0.0:8000
\ No newline at end of file
a:hover,a:link,a:visited{text-decoration:none}
\ No newline at end of file
This diff could not be displayed because it is too large.
No preview for this file type
<!DOCTYPE html><html lang=en><head><meta charset=utf-8><meta http-equiv=X-UA-Compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1"><link rel=icon href=/favicon.ico><title>Profit-Hunter</title><link href=/css/app.1dc1d4aa.css rel=preload as=style><link href=/css/chunk-vendors.abb36e73.css rel=preload as=style><link href=/js/app.c2c9928d.js rel=preload as=script><link href=/js/chunk-vendors.f428e429.js rel=preload as=script><link href=/css/chunk-vendors.abb36e73.css rel=stylesheet><link href=/css/app.1dc1d4aa.css rel=stylesheet></head><body><noscript><strong>We're sorry but front doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id=app></div><script src=/js/chunk-vendors.f428e429.js></script><script src=/js/app.c2c9928d.js></script></body></html>
\ No newline at end of file
<template>
<v-sheet>
<v-overlay v-model="loadingProcess">
<v-progress-circular :size="120" width="10" color="primary" indeterminate></v-progress-circular>
<div style="color: #ffffff; font-size: 18px; margin-top: 10px">Analyzing Your Video...</div>
</v-overlay>
<v-layout justify-center>
<v-flex xs12 sm8 md6 lg4>
<v-row justify="center" class="mx-0 mt-12">
......@@ -109,7 +113,7 @@ export default {
generatedTag: [],
successDialog: false,
errorDialog: false,
loading: false,
loadingProcess: false,
};
},
created() {
......@@ -120,12 +124,12 @@ export default {
methods: {
loadVideoInfo() {},
uploadVideo(files) {
console.log(files[0]);
this.loadingProcess = true;
const formData = new FormData();
formData.append('file', files[0]);
this.$axios.post('/upload', formData, { headers: { 'Content-Type': 'multipart/form-data' } })
.then((r) => {
this.loading = true;
this.loadingProcess = false;
console.log(r);
})
.catch((e) => {
......