Yoonjunhyeon

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

Showing 75 changed files with 187 additions and 100 deletions
...@@ -18,9 +18,9 @@ MEDIA_ROOT = os.path.join(BASE_DIR, 'media') ...@@ -18,9 +18,9 @@ MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
18 def file_upload_path( filename): 18 def file_upload_path( filename):
19 ext = filename.split('.')[-1] 19 ext = filename.split('.')[-1]
20 d = datetime.datetime.now() 20 d = datetime.datetime.now()
21 - filepath = d.strftime('%Y\\%m\\%d') 21 + filepath = d.strftime('%Y-%m-%d')
22 suffix = d.strftime("%Y%m%d%H%M%S") 22 suffix = d.strftime("%Y%m%d%H%M%S")
23 - filename = "%s_%s.%s"%(uuid.uuid4().hex, suffix, ext) 23 + filename = "%s.%s"%(suffix, ext)
24 return os.path.join( MEDIA_ROOT , filepath, filename) 24 return os.path.join( MEDIA_ROOT , filepath, filename)
25 25
26 # DB 필드에서 호출 26 # DB 필드에서 호출
......
...@@ -12,6 +12,8 @@ from django.shortcuts import get_object_or_404, render ...@@ -12,6 +12,8 @@ from django.shortcuts import get_object_or_404, render
12 from api.models import Video, VideoFile 12 from api.models import Video, VideoFile
13 from api.serializers import VideoSerializer, VideoFileSerializer 13 from api.serializers import VideoSerializer, VideoFileSerializer
14 from api import file_upload_path 14 from api import file_upload_path
15 +import subprocess
16 +import shlex
15 17
16 # Create your views here. 18 # Create your views here.
17 19
...@@ -23,6 +25,9 @@ class VideoViewSet(viewsets.ModelViewSet): ...@@ -23,6 +25,9 @@ class VideoViewSet(viewsets.ModelViewSet):
23 serializer_class = VideoSerializer 25 serializer_class = VideoSerializer
24 26
25 27
28 +
29 +
30 +
26 class VideoFileViewSet(viewsets.ModelViewSet): 31 class VideoFileViewSet(viewsets.ModelViewSet):
27 queryset = VideoFile.objects.all() 32 queryset = VideoFile.objects.all()
28 serializer_class = VideoFileSerializer 33 serializer_class = VideoFileSerializer
...@@ -37,18 +42,19 @@ class VideoFileUploadView(APIView): ...@@ -37,18 +42,19 @@ class VideoFileUploadView(APIView):
37 return Response(serializer.data) 42 return Response(serializer.data)
38 43
39 def post(self, req, *args, **kwargs): 44 def post(self, req, *args, **kwargs):
45 + # 동영상 길이
46 + runTime = 126
40 # 요청된 데이터를 꺼냄( QueryDict) 47 # 요청된 데이터를 꺼냄( QueryDict)
41 new_data = req.data.dict() 48 new_data = req.data.dict()
42 49
43 # 요청된 파일 객체 50 # 요청된 파일 객체
44 - print(req.data)
45 file_name = req.data['file'] 51 file_name = req.data['file']
46 52
47 # 저장될 파일의 풀path를 생성 53 # 저장될 파일의 풀path를 생성
48 new_file_full_name = file_upload_path(file_name.name) 54 new_file_full_name = file_upload_path(file_name.name)
49 - 55 + print(new_file_full_name)
50 # 새롭게 생성된 파일의 경로 56 # 새롭게 생성된 파일의 경로
51 - file_path = '\\'.join(new_file_full_name.split('\\')[0:-1]) 57 + file_path = '-'.join(new_file_full_name.split('-')[0:-1])
52 58
53 new_data['file_path'] = file_path 59 new_data['file_path'] = file_path
54 new_data['file_origin_name'] = req.data['file'].name 60 new_data['file_origin_name'] = req.data['file'].name
...@@ -56,12 +62,15 @@ class VideoFileUploadView(APIView): ...@@ -56,12 +62,15 @@ class VideoFileUploadView(APIView):
56 62
57 new_query_dict = QueryDict('', mutable=True) 63 new_query_dict = QueryDict('', mutable=True)
58 new_query_dict.update(new_data) 64 new_query_dict.update(new_data)
59 -
60 file_serializer = VideoFileSerializer(data = new_query_dict) 65 file_serializer = VideoFileSerializer(data = new_query_dict)
66 +
61 if file_serializer.is_valid(): 67 if file_serializer.is_valid():
62 file_serializer.save() 68 file_serializer.save()
63 print(file_serializer.data) 69 print(file_serializer.data)
64 70
71 + process = subprocess.Popen(['./runMediaPipe.sh %s %s' %(file_serializer.data['file_save_name'],runTime,)], shell = True)
72 + process.wait()
73 +
65 return Response(True, status=status.HTTP_201_CREATED) 74 return Response(True, status=status.HTTP_201_CREATED)
66 else: 75 else:
67 return Response(file_serializer.errors, status=status.HTTP_400_BAD_REQUEST) 76 return Response(file_serializer.errors, status=status.HTTP_400_BAD_REQUEST)
......
1 +import tensorflow as tf
2 +import glob, os
3 +import numpy
4 +
5 +def _make_bytes(int_array):
6 + if bytes == str: # Python2
7 + return ''.join(map(chr, int_array))
8 + else:
9 + return bytes(int_array)
10 +
11 +
12 +def quantize(features, min_quantized_value=-2.0, max_quantized_value=2.0):
13 + """Quantizes float32 `features` into string."""
14 + assert features.dtype == 'float32'
15 + assert len(features.shape) == 1 # 1-D array
16 + features = numpy.clip(features, min_quantized_value, max_quantized_value)
17 + quantize_range = max_quantized_value - min_quantized_value
18 + features = (features - min_quantized_value) * (255.0 / quantize_range)
19 + features = [int(round(f)) for f in features]
20 +
21 + return _make_bytes(features)
22 +
23 +
24 +# for parse feature.pb
25 +
26 +contexts = {
27 + 'AUDIO/feature/dimensions': tf.io.FixedLenFeature([], tf.int64),
28 + 'AUDIO/feature/rate': tf.io.FixedLenFeature([], tf.float32),
29 + 'RGB/feature/dimensions': tf.io.FixedLenFeature([], tf.int64),
30 + 'RGB/feature/rate': tf.io.FixedLenFeature([], tf.float32),
31 + 'clip/data_path': tf.io.FixedLenFeature([], tf.string),
32 + 'clip/end/timestamp': tf.io.FixedLenFeature([], tf.int64),
33 + 'clip/start/timestamp': tf.io.FixedLenFeature([], tf.int64)
34 +}
35 +
36 +features = {
37 + 'AUDIO/feature/floats': tf.io.VarLenFeature(dtype=tf.float32),
38 + 'AUDIO/feature/timestamp': tf.io.VarLenFeature(tf.int64),
39 + 'RGB/feature/floats': tf.io.VarLenFeature(dtype=tf.float32),
40 + 'RGB/feature/timestamp': tf.io.VarLenFeature(tf.int64)
41 +
42 +}
43 +
44 +
45 +def parse_exmp(serial_exmp):
46 + _, sequence_parsed = tf.io.parse_single_sequence_example(
47 + serialized=serial_exmp,
48 + context_features=contexts,
49 + sequence_features=features)
50 +
51 + sequence_parsed = tf.contrib.learn.run_n(sequence_parsed)[0]
52 +
53 + audio = sequence_parsed['AUDIO/feature/floats'].values
54 + rgb = sequence_parsed['RGB/feature/floats'].values
55 +
56 + # print(audio.values)
57 + # print(type(audio.values))
58 +
59 + # audio is 128 8bit, rgb is 1024 8bit for every second
60 + audio_slices = [audio[128 * i: 128 * (i + 1)] for i in range(len(audio) // 128)]
61 + rgb_slices = [rgb[1024 * i: 1024 * (i + 1)] for i in range(len(rgb) // 1024)]
62 +
63 + byte_audio = []
64 + byte_rgb = []
65 +
66 + for seg in audio_slices:
67 + audio_seg = quantize(seg)
68 + byte_audio.append(audio_seg)
69 +
70 + for seg in rgb_slices:
71 + rgb_seg = quantize(seg)
72 + byte_rgb.append(rgb_seg)
73 +
74 + return byte_audio, byte_rgb
75 +
76 +
77 +def make_exmp(id, labels, audio, rgb):
78 + audio_features = []
79 + rgb_features = []
80 +
81 + for embedding in audio:
82 + embedding_feature = tf.train.Feature(
83 + bytes_list=tf.train.BytesList(value=[embedding]))
84 + audio_features.append(embedding_feature)
85 +
86 + for embedding in rgb:
87 + embedding_feature = tf.train.Feature(
88 + bytes_list=tf.train.BytesList(value=[embedding]))
89 + rgb_features.append(embedding_feature)
90 +
91 + # for construct yt8m data
92 + seq_exmp = tf.train.SequenceExample(
93 + context=tf.train.Features(
94 + feature={
95 + 'id': tf.train.Feature(bytes_list=tf.train.BytesList(
96 + value=[id.encode('utf-8')])),
97 + 'labels': tf.train.Feature(int64_list=tf.train.Int64List(
98 + value=[labels]))
99 + }),
100 + feature_lists=tf.train.FeatureLists(
101 + feature_list={
102 + 'audio': tf.train.FeatureList(
103 + feature=audio_features
104 + ),
105 + 'rgb': tf.train.FeatureList(
106 + feature=rgb_features
107 + )
108 + })
109 + )
110 + serialized = seq_exmp.SerializeToString()
111 + return serialized
112 +
113 +
114 +if __name__ == '__main__':
115 + filename = '/tmp/mediapipe/features.pb'
116 +
117 + sequence_example = open(filename, 'rb').read()
118 +
119 + audio, rgb = parse_exmp(sequence_example)
120 +
121 + id = 'test_001'
122 +
123 + labels = 1
124 +
125 + tmp_example = make_exmp(id, labels, audio, rgb)
126 +
127 + decoded = tf.train.SequenceExample.FromString(tmp_example)
128 + print(decoded)
129 +
130 + # then you can write tmp_example to tfrecord files
...\ No newline at end of file ...\ No newline at end of file
...@@ -28,7 +28,7 @@ deactivate () { ...@@ -28,7 +28,7 @@ deactivate () {
28 fi 28 fi
29 29
30 unset VIRTUAL_ENV 30 unset VIRTUAL_ENV
31 - if [ ! "$1" = "nondestructive" ] ; then 31 + if [ ! "${1:-}" = "nondestructive" ] ; then
32 # Self destruct! 32 # Self destruct!
33 unset -f deactivate 33 unset -f deactivate
34 fi 34 fi
...@@ -37,7 +37,7 @@ deactivate () { ...@@ -37,7 +37,7 @@ deactivate () {
37 # unset irrelevant variables 37 # unset irrelevant variables
38 deactivate nondestructive 38 deactivate nondestructive
39 39
40 -VIRTUAL_ENV="/home/jun/documents/Univ/PKH_Project1/web/backend/env" 40 +VIRTUAL_ENV="/home/jun/documents/univ/PKH_Project1/web/backend/env"
41 export VIRTUAL_ENV 41 export VIRTUAL_ENV
42 42
43 _OLD_VIRTUAL_PATH="$PATH" 43 _OLD_VIRTUAL_PATH="$PATH"
......
...@@ -8,7 +8,7 @@ alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PA ...@@ -8,7 +8,7 @@ alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PA
8 # Unset irrelevant variables. 8 # Unset irrelevant variables.
9 deactivate nondestructive 9 deactivate nondestructive
10 10
11 -setenv VIRTUAL_ENV "/home/jun/documents/Univ/PKH_Project1/web/backend/env" 11 +setenv VIRTUAL_ENV "/home/jun/documents/univ/PKH_Project1/web/backend/env"
12 12
13 set _OLD_VIRTUAL_PATH="$PATH" 13 set _OLD_VIRTUAL_PATH="$PATH"
14 setenv PATH "$VIRTUAL_ENV/bin:$PATH" 14 setenv PATH "$VIRTUAL_ENV/bin:$PATH"
......
...@@ -29,7 +29,7 @@ end ...@@ -29,7 +29,7 @@ end
29 # unset irrelevant variables 29 # unset irrelevant variables
30 deactivate nondestructive 30 deactivate nondestructive
31 31
32 -set -gx VIRTUAL_ENV "/home/jun/documents/Univ/PKH_Project1/web/backend/env" 32 +set -gx VIRTUAL_ENV "/home/jun/documents/univ/PKH_Project1/web/backend/env"
33 33
34 set -gx _OLD_VIRTUAL_PATH $PATH 34 set -gx _OLD_VIRTUAL_PATH $PATH
35 set -gx PATH "$VIRTUAL_ENV/bin" $PATH 35 set -gx PATH "$VIRTUAL_ENV/bin" $PATH
......
1 -#!/home/jun/documents/Univ/PKH_Project1/web/backend/env/bin/python3
2 -
3 -# -*- coding: utf-8 -*-
4 -import re
5 -import sys
6 -
7 -from autopep8 import main
8 -
9 -if __name__ == '__main__':
10 - sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
11 - sys.exit(main())
1 -#!/home/jun/documents/Univ/PKH_Project1/web/backend/env/bin/python 1 +#!/home/jun/documents/univ/PKH_Project1/web/backend/env/bin/python
2 -
3 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
4 import re 3 import re
5 import sys 4 import sys
6 -
7 from django.core.management import execute_from_command_line 5 from django.core.management import execute_from_command_line
8 -
9 if __name__ == '__main__': 6 if __name__ == '__main__':
10 - sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) 7 + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
11 sys.exit(execute_from_command_line()) 8 sys.exit(execute_from_command_line())
......
1 -#!/home/jun/documents/Univ/PKH_Project1/web/backend/env/bin/python 1 +#!/home/jun/documents/univ/PKH_Project1/web/backend/env/bin/python
2 from django.core import management 2 from django.core import management
3 3
4 if __name__ == "__main__": 4 if __name__ == "__main__":
......
1 -#!/home/jun/documents/Univ/PKH_Project1/web/backend/env/bin/python 1 +#!/home/jun/documents/univ/PKH_Project1/web/backend/env/bin/python
2 -
3 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
4 import re 3 import re
5 import sys 4 import sys
6 -
7 from setuptools.command.easy_install import main 5 from setuptools.command.easy_install import main
8 -
9 if __name__ == '__main__': 6 if __name__ == '__main__':
10 - sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) 7 + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
11 sys.exit(main()) 8 sys.exit(main())
......
1 -#!/home/jun/documents/Univ/PKH_Project1/web/backend/env/bin/python
2 -
3 -# -*- coding: utf-8 -*-
4 -import re
5 -import sys
6 -
7 -from setuptools.command.easy_install import main
8 -
9 -if __name__ == '__main__':
10 - sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
11 - sys.exit(main())
1 -#!/home/jun/documents/Univ/PKH_Project1/web/backend/env/bin/python 1 +#!/home/jun/documents/univ/PKH_Project1/web/backend/env/bin/python
2 -
3 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
4 import re 3 import re
5 import sys 4 import sys
6 - 5 +from pip._internal.cli.main import main
7 -from pip import main
8 -
9 if __name__ == '__main__': 6 if __name__ == '__main__':
10 - sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) 7 + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
11 sys.exit(main()) 8 sys.exit(main())
......
1 -#!/home/jun/documents/Univ/PKH_Project1/web/backend/env/bin/python 1 +#!/home/jun/documents/univ/PKH_Project1/web/backend/env/bin/python
2 -
3 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
4 import re 3 import re
5 import sys 4 import sys
6 - 5 +from pip._internal.cli.main import main
7 -from pip import main
8 -
9 if __name__ == '__main__': 6 if __name__ == '__main__':
10 - sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) 7 + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
11 sys.exit(main()) 8 sys.exit(main())
......
1 -#!/home/jun/documents/Univ/PKH_Project1/web/backend/env/bin/python
2 -
3 -# -*- coding: utf-8 -*-
4 -import re
5 -import sys
6 -
7 -from pip import main
8 -
9 -if __name__ == '__main__':
10 - sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
11 - sys.exit(main())
1 -#!/home/jun/documents/Univ/PKH_Project1/web/backend/env/bin/python3
2 -
3 -# -*- coding: utf-8 -*-
4 -import re
5 -import sys
6 -
7 -from pycodestyle import _main
8 -
9 -if __name__ == '__main__':
10 - sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
11 - sys.exit(_main())
1 -#!/home/jun/documents/Univ/PKH_Project1/web/backend/env/bin/python 1 +#!/home/jun/documents/univ/PKH_Project1/web/backend/env/bin/python
2 -
3 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
4 import re 3 import re
5 import sys 4 import sys
6 -
7 from sqlparse.__main__ import main 5 from sqlparse.__main__ import main
8 -
9 if __name__ == '__main__': 6 if __name__ == '__main__':
10 - sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0]) 7 + sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
11 sys.exit(main()) 8 sys.exit(main())
......
1 home = /usr/bin 1 home = /usr/bin
2 include-system-site-packages = false 2 include-system-site-packages = false
3 -version = 3.6.9 3 +version = 3.8.2
......
1 +#!/bin/bash
2 +cd ../../../mediapipe
3 +. venv/bin/activate
4 +
5 +/usr/local/bazel/2.0.0/lib/bazel/bin/bazel version && \
6 +alias bazel='/usr/local/bazel/2.0.0/lib/bazel/bin/bazel'
7 +
8 +python -m mediapipe.examples.desktop.youtube8m.generate_input_sequence_example \
9 + --path_to_input_video=/$1 \
10 + --clip_end_time_sec=$2
11 +
12 +GLOG_logtostderr=1 bazel-bin/mediapipe/examples/desktop/youtube8m/extract_yt8m_features \
13 + --calculator_graph_config_file=mediapipe/graphs/youtube8m/feature_extraction.pbtxt \
14 + --input_side_packets=input_sequence_example=/tmp/mediapipe/metadata.pb \
15 + --output_side_packets=output_sequence_example=/tmp/mediapipe/features.pb
16 +
17 +python convertPb2Tfrecord.py
...\ No newline at end of file ...\ No newline at end of file
1 -#!/bin/bash
2 -. env/bin/activate
3 -pip3 install -r requirements.txt
4 -rm -rf static
5 -./manage.py collectstatic
6 -rm -rf static/admin
7 -rm -rf static/rest_framework
8 -
9 -python manage.py makemigrations
10 -python manage.py migrate
11 -python vue2djangoTemplate.py
12 -python manage.py runserver 0.0.0.0:8000
...\ No newline at end of file ...\ No newline at end of file
1 -a:hover,a:link,a:visited{text-decoration:none}
...\ No newline at end of file ...\ No newline at end of file
This diff could not be displayed because it is too large.
No preview for this file type
1 -<!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 ...\ No newline at end of file
1 <template> 1 <template>
2 <v-sheet> 2 <v-sheet>
3 + <v-overlay v-model="loadingProcess">
4 + <v-progress-circular :size="120" width="10" color="primary" indeterminate></v-progress-circular>
5 + <div style="color: #ffffff; font-size: 18px; margin-top: 10px">Analyzing Your Video...</div>
6 + </v-overlay>
3 <v-layout justify-center> 7 <v-layout justify-center>
4 <v-flex xs12 sm8 md6 lg4> 8 <v-flex xs12 sm8 md6 lg4>
5 <v-row justify="center" class="mx-0 mt-12"> 9 <v-row justify="center" class="mx-0 mt-12">
...@@ -109,7 +113,7 @@ export default { ...@@ -109,7 +113,7 @@ export default {
109 generatedTag: [], 113 generatedTag: [],
110 successDialog: false, 114 successDialog: false,
111 errorDialog: false, 115 errorDialog: false,
112 - loading: false, 116 + loadingProcess: false,
113 }; 117 };
114 }, 118 },
115 created() { 119 created() {
...@@ -120,12 +124,12 @@ export default { ...@@ -120,12 +124,12 @@ export default {
120 methods: { 124 methods: {
121 loadVideoInfo() {}, 125 loadVideoInfo() {},
122 uploadVideo(files) { 126 uploadVideo(files) {
123 - console.log(files[0]); 127 + this.loadingProcess = true;
124 const formData = new FormData(); 128 const formData = new FormData();
125 formData.append('file', files[0]); 129 formData.append('file', files[0]);
126 this.$axios.post('/upload', formData, { headers: { 'Content-Type': 'multipart/form-data' } }) 130 this.$axios.post('/upload', formData, { headers: { 'Content-Type': 'multipart/form-data' } })
127 .then((r) => { 131 .then((r) => {
128 - this.loading = true; 132 + this.loadingProcess = false;
129 console.log(r); 133 console.log(r);
130 }) 134 })
131 .catch((e) => { 135 .catch((e) => {
......