윤영빈

made it run

mediapipe @ 8ed8b529
Subproject commit 8ed8b52992cd8b25cbc8a25c1513ed0a0809de87
......@@ -18,8 +18,9 @@ import shlex
import json
# Create your views here.
import sys
sys.path.insert(0, "/khuhub/2015104192/web/backend/yt8m/esot3ria")
sys.path.insert(0, "/mnt/e/khuhub/2015104192/web/backend/yt8m/esot3ria")
import inference_pb
import pb_util as pbutil
def with_ffprobe(filename):
......@@ -77,16 +78,16 @@ class VideoFileUploadView(APIView):
file_serializer.save()
# 동영상 길이 출력
fileFullName = file_serializer.data['file_save_name']
fileProcessedName = fileFullName.replace("%3A",":")
print('FILE======================================================= ' + fileFullName)
fileProcessedName = fileFullName.replace("E%3A","")
print('FILE======================================================= ' + fileProcessedName)
runTime = with_ffprobe(fileProcessedName)
print('RUNTIME ::::==== ' + str(runTime))
print(threshold)
print('CURR DIR = ' + os.getcwd())
process = subprocess.Popen(['./runMediaPipe.sh %s %s' %(fileProcessedName,runTime,)], shell = True)
print('runtime = ' + str(runTime))
process = subprocess.Popen(["sh runMediaPipe.sh %s %d " %(fileProcessedName,runTime)], shell = True)
process.wait()
result = inference_pb.inference_pb('E:/khuhub/2015104192/web/backend/yt8m/featuremaps/features(baby_samoyed).pb', threshold)
print("NOW DONE name = " + fileProcessedName + " / thresh = " + str(threshold))
result = inference_pb.inference_pb("/tmp/mediapipe/features.pb", threshold)
return Response(result, status=status.HTTP_201_CREATED)
else:
......
This file is too large to display.
#!/bin bash
cd ../../mediapipe
echo "${PWD}"
\ No newline at end of file
#!/bin/bash
cd ../../../../mediapipe
echo "${PWD}"
cd ../../mediapipe/mediapipe
. venv/bin/activate
echo "STEP1"
bazel version && \
alias bazel='bazel'
echo "STEP2"
echo "activated"
/usr/local/bazel/3.4.0/lib/bazel/bin/bazel version && \
alias bazel='/usr/local/bazel/3.4.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
echo "STEP3"
GLOG_logtostderr=1 /mediapipe/examples/desktop/youtube8m/extract_yt8m_features \
echo "Nocly done"
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
echo "COMPLETED"
sleep 5
\ No newline at end of file
--output_side_packets=output_sequence_example=/tmp/mediapipe/features.pb
\ No newline at end of file
......
#!/bin bash
cd ../../../mediapipe
. venv/bin/activate
/usr/local/bazel/3.4.0/lib/bazel/bin/bazel version && \
alias bazel='/usr/local/bazel/3.4.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
\ No newline at end of file
{"model": "FrameLevelLogisticModel", "feature_sizes": "1024,128", "feature_names": "rgb,audio", "frame_features": true, "label_loss": "CrossEntropyLoss"}
\ No newline at end of file
......@@ -9,12 +9,12 @@ import video_recommender as recommender
import video_util as videoutil
# Define file paths.
MODEL_PATH = "E:/khuhub/2015104192/web/backend/yt8m/esot3ria/model/inference_model/segment_inference_model"
VOCAB_PATH = "E:/khuhub/2015104192/web/backend/yt8m/vocabulary.csv"
VIDEO_TAGS_PATH = "E:/khuhub/2015104192/web/backend/yt8m/esot3ria/kaggle_solution_40k.csv"
TAG_VECTOR_MODEL_PATH = "E:/khuhub/2015104192/web/backend/yt8m/esot3ria/tag_vectors.model"
VIDEO_VECTOR_MODEL_PATH = "E:/khuhub/2015104192/web/backend/yt8m/esot3ria/video_vectors.model"
SEGMENT_LABEL_PATH = "E:/khuhub/2015104192/web/backend/yt8m/segment_label_ids.csv"
MODEL_PATH = "/mnt/e/khuhub/2015104192/web/backend/yt8m/esot3ria/model/inference_model/segment_inference_model"
VOCAB_PATH = "/mnt/e/khuhub/2015104192/web/backend/yt8m/vocabulary.csv"
VIDEO_TAGS_PATH = "/mnt/e/khuhub/2015104192/web/backend/yt8m/esot3ria/kaggle_solution_40k.csv"
TAG_VECTOR_MODEL_PATH = "/mnt/e/khuhub/2015104192/web/backend/yt8m/esot3ria/tag_vectors.model"
VIDEO_VECTOR_MODEL_PATH = "/mnt/e/khuhub/2015104192/web/backend/yt8m/esot3ria/video_vectors.model"
SEGMENT_LABEL_PATH = "/mnt/e/khuhub/2015104192/web/backend/yt8m/segment_label_ids.csv"
# Define parameters.
TAG_TOP_K = 5
......@@ -89,11 +89,12 @@ def inference_pb(file_path, threshold):
print("started step 1")
VIDEO_TOP_K = int(threshold)
inference_result = {}
print("STEP ==== 1")
with tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) as sess:
print("STEP ==== 1.5 " + file_path)
# 0. Import SequenceExample type target from pb.
target_video = pbutil.convert_pb(file_path)
print("STEP ==== 2")
# 1. Load video features from pb.
video_id_batch_val = np.array([b'video'])
n_frames = len(target_video.feature_lists.feature_list['rgb'].feature)
......@@ -109,13 +110,13 @@ def inference_pb(file_path, threshold):
video_batch_val[i] = np.concatenate([video_batch_rgb, video_batch_audio], axis=0)
video_batch_val = np.array([video_batch_val])
num_frames_batch_val = np.array([n_frames])
print("STEP ==== 3")
# Restore checkpoint and meta-graph file.
if not gfile.Exists(MODEL_PATH + ".meta"):
raise IOError("Cannot find %s. Did you run eval.py?" % MODEL_PATH)
meta_graph_location = MODEL_PATH + ".meta"
logging.info("loading meta-graph: " + meta_graph_location)
print("STEP ==== 4")
with tf.device("/cpu:0"):
saver = tf.train.import_meta_graph(meta_graph_location, clear_devices=True)
logging.info("restoring variables from " + MODEL_PATH)
......@@ -123,7 +124,7 @@ def inference_pb(file_path, threshold):
input_tensor = tf.get_collection("input_batch_raw")[0]
num_frames_tensor = tf.get_collection("num_frames")[0]
predictions_tensor = tf.get_collection("predictions")[0]
print("STEP ==== 5")
# Workaround for num_epochs issue.
def set_up_init_ops(variables):
init_op_list = []
......@@ -133,10 +134,10 @@ def inference_pb(file_path, threshold):
variables.remove(variable)
init_op_list.append(tf.variables_initializer(variables))
return init_op_list
print("STEP ==== 6")
sess.run(
set_up_init_ops(tf.get_collection_ref(tf.GraphKeys.LOCAL_VARIABLES)))
print("STEP ==== 7")
whitelisted_cls_mask = np.zeros((predictions_tensor.get_shape()[-1],),
dtype=np.float32)
with tf.io.gfile.GFile(SEGMENT_LABEL_PATH) as fobj:
......@@ -221,5 +222,5 @@ def inference_pb(file_path, threshold):
if __name__ == '__main__':
filepath = "/tmp/mediapipe/features.pb"
result = inference_pb(filepath)
result = inference_pb(filepath,5)
print(result)
......
import tensorflow as tf
import numpy
import pickle
def _make_bytes(int_array):
......@@ -43,17 +44,20 @@ features = {
def parse_exmp(serial_exmp):
print("CAME IN SECOND======111111 : ")
_, 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]
print("CAME IN SECOND=====222222 := ")
sequence_parsed = tf.contrib.learn.run_n(sequence_parsed, n=1, feed_dict=None)[0]
print("CAME IN SECOND=====3333333")
audio = sequence_parsed['AUDIO/feature/floats'].values
print("CAME IN SECOND=====44444444")
rgb = sequence_parsed['RGB/feature/floats'].values
# print(audio.values)
print("CAME IN SECOND=====5555555")
print("======AUDIO=======")
print(audio)
# print(type(audio.values))
# audio is 128 8bit, rgb is 1024 8bit for every second
......@@ -112,9 +116,21 @@ def make_exmp(id, audio, rgb):
def convert_pb(filename):
print("==============")
print("CAME IN! " + filename)
print("==============")
sequence_example = open(filename, 'rb').read()
print("==============")
print("IM 1 ::: ")
print("==============")
audio, rgb = parse_exmp(sequence_example)
print("==============")
print("IM 2")
print("==============")
tmp_example = make_exmp('video', audio, rgb)
print("==============")
print("IM 3")
print("==============")
decoded = tf.train.SequenceExample.FromString(tmp_example)
print("DECODE COMPLETE")
return decoded
......
......@@ -12,6 +12,8 @@ def getURL(vid_id):
return youtube_url + response.text[10:-3]
print(getURL('udtT'))
def getVideoInfo(vid_id, video_tags_path, top_k):
video_url = getURL(vid_id)
......
......@@ -33,7 +33,7 @@ FLAGS = flags.FLAGS
if __name__ == "__main__":
# Dataset flags.
flags.DEFINE_string(
"train_dir", "/tmp/yt8m_model/",
"train_dir", "F:/yt8mDataset/savedModel",
"The directory to load the model files from. "
"The tensorboard metrics files are also saved to this "
"directory.")
......
......@@ -85,7 +85,7 @@ if __name__ == "__main__":
flags.DEFINE_integer("top_k", 5, "How many predictions to output per video.")
# Other flags.
flags.DEFINE_integer("batch_size", 512,
flags.DEFINE_integer("batch_size", 32,
"How many examples to process per batch.")
flags.DEFINE_integer("num_readers", 1,
"How many threads to use for reading input files.")
......@@ -276,7 +276,7 @@ def inference(reader, train_dir, data_pattern, out_file_location, batch_size,
#open vocab csv file and store to dictionary
#=========================================
voca_dict = {}
vocabs = open("./vocabulary.csv", 'r')
vocabs = open("./vocabulary.csv", 'r',encoding='UTF8')
while True:
line = vocabs.readline()
if not line: break
......
......@@ -75,7 +75,7 @@ if __name__ == "__main__":
flags.DEFINE_integer(
"num_gpu", 1, "The maximum number of GPU devices to use for training. "
"Flag only applies if GPUs are installed")
flags.DEFINE_integer("batch_size", 128,
flags.DEFINE_integer("batch_size", 64,
"How many examples to process per batch for training.")
flags.DEFINE_string("label_loss", "CrossEntropyLoss",
"Which loss function to use for training the model.")
......@@ -83,14 +83,14 @@ if __name__ == "__main__":
"regularization_penalty", 1.0,
"How much weight to give to the regularization loss (the label loss has "
"a weight of 1).")
flags.DEFINE_float("base_learning_rate", 0.001,
flags.DEFINE_float("base_learning_rate", 0.002,
"Which learning rate to start with.")
flags.DEFINE_float(
"learning_rate_decay", 0.8,
"Learning rate decay factor to be applied every "
"learning_rate_decay_examples.")
flags.DEFINE_float(
"learning_rate_decay_examples", 100,
"learning_rate_decay_examples", 70,
"Multiply current learning rate by learning_rate_decay "
"every learning_rate_decay_examples.")
flags.DEFINE_integer(
......@@ -100,7 +100,7 @@ if __name__ == "__main__":
"max_steps", None,
"The maximum number of iterations of the training loop.")
flags.DEFINE_integer(
"export_model_steps", 100,
"export_model_steps", 5,
"The period, in number of steps, with which the model "
"is exported for batch prediction.")
......
캡1때 했던 컨셉들은 간단하게 적고 넘어간다
1. 여러가지 모델로 학습을 해보고 제일 좋은거 고르자
1.5 워드벡터 임베딩에 쓸 말뭉치 좋은거 쓰자
2. 태그의 weight를 어떻게 조절을 해보자
(3. 성능(시간복잡도) 향상)
\ No newline at end of file