이태현

func_edit2

This diff could not be displayed because it is too large.
결과
커널크기/비디오 수/캡2/캡1
1/260/29/31 -> 129/131
3/260/32/30 -> 131/129
5/260/36/24 -> 136/124
7/260/35/25 -> 135/125
\ No newline at end of file
import math
import numpy as np
def softmax(inputA):
result = []
......@@ -23,6 +24,34 @@ def softmax(inputA):
#result = normalize(result)
return result
def softmax2(input2):
result = []
sigmaSum = 0
normalized_arr = []
'''
for x in inputA:
normalized_arr.append(float(x))
normalized_arr = normalize(normalized_arr)
for i in range(0, len(normalized_arr)):
powA = pow(math.e, normalized_arr[i])
sigmaSum = sigmaSum + powA
for i in range(0, len(normalized_arr)):
powB = pow(math.e, normalized_arr[i])
resultA = powB / sigmaSum
result.append(resultA)
'''
result = np.exp(normalized_arr) / sum(np.exp(normalized_arr))
#result = normalize(result)
return result
def normalize(arrs):
normalized_arr = []
for x in arrs:
......
......@@ -355,7 +355,94 @@ def test(tag_model_path, video_model_path, video_id_model, video_tags_path, segm
segmentTagList.append(tagList)
#===========
def printSimilar(video_vector):
video_ids = Word2Vec().wv.load("./video_vectors.model")
similar_ids = [x[0] for x in video_ids.similar_by_vector(video_vector, 5)]
similar_prob = [x[1] for x in video_ids.similar_by_vector(video_vector, 5)]
print(similar_ids) # 추천 받은 영상들 유사도들도 출력시켜서 1학기 결과 / 지금 결과 유사도끼리 비교하면 됨
print(similar_prob)
return max(similar_prob)
def testWithSoftmax():
tag_vectors = Word2Vec.load("./tag_vectors.model").wv # 내 디렉토리로 바꿔야함
entire_video_tags = pd.read_csv("./kaggle_solution_40k.csv",encoding='utf8')
countScore = 0
countComp = 0
video_vector = np.zeros(100)
video_vector2 = np.zeros(100)
tag_preds =[]
tag_preds2 =[]
videoTagList = []
prevVideoId = ""
for i, row in entire_video_tags.iterrows():
video_id = row[0]
if video_id == "vid_id":
continue
if prevVideoId == "":
prevVideoId = video_id
if video_id[0:4] != prevVideoId[0:4]:
count = {}
cap1 = 0
cap2 = 0
totalSegmentTagProbList = []
for segTag in row[1:]:
segTag = segTag.split(":")
segmentTagProbList = []
for i in range(0,len(segTag)):
try: count[segTag[0]] += float(segTag[1])
except: count[segTag[0]] = float(segTag[1])
segmentTagProbList.append(segTag[0])
segmentTagProbList.append(segTag[1])
totalSegmentTagProbList.append(segmentTagProbList)
sorted(count.items(), key=lambda x: x[1], reverse=True)
tagnames = list(count.keys())[0:5]
tagprobs = list(count.values())[0:5]
tags = zip(tagnames,tagprobs)
for (tag, weight) in tags:
tag_preds.append(weight)
tag_preds2.append(weight)
tag_preds = ac.softmax(tag_preds)
videoTagList.append(tag)
#ac.softmax2(tag_preds)
for tag,pred,pred2 in zip(tagnames,tag_preds,tag_preds2):
#print(tag,pred)
if tag in tag_vectors.vocab:
video_vector = video_vector + (tag_vectors[tag] * float(pred))
video_vector2 = video_vector2 + (tag_vectors[tag] * float(pred2))
print(tag)
withSoftmax = printSimilar(video_vector)
withoutSoftmax = printSimilar(video_vector2)
print("Final Score: ", countScore)
print("Comparison time: ", countComp)
return countScore
def TestAll():
testWithSoftmax()
def rlTest():
sumVar = 50
a = 35
b = sumVar - a
print('----------------------------------------------------')
print('ScoreWithSoftmax : ', a, ' ScoreWithoutSoftmax : ', b)
print('----------------------------------------------------')
VIDEO_TAGS_PATH = "/mnt/e/khuhub/2015104192/web/backend/yt8m/esot3ria/segment_tags.csv"
VIDEO_IDS_PATH = "/mnt/e/khuhub/2015104192/web/backend/yt8m/esot3ria/videoIds.csv"
TAG_VECTOR_MODEL_PATH = "/mnt/e/khuhub/2015104192/web/backend/yt8m/esot3ria/tag_vectors.model"
......@@ -364,11 +451,14 @@ VIDEO_VECTOR_MODEL2_PATH = "/mnt/e/khuhub/2015104192/web/backend/yt8m/esot3ria/v
VIDEO_ID_MODEL_PATH = "/mnt/e/khuhub/2015104192/web/backend/yt8m/esot3ria/videoId_vectors.model"
TEST_TAGS_PATH = "/mnt/e/khuhub/2015104192/web/backend/yt8m/esot3ria/test_segement_tags.csv"
'''
test(TAG_VECTOR_MODEL_PATH,
VIDEO_VECTOR_MODEL_PATH,
VIDEO_ID_MODEL_PATH,
VIDEO_IDS_PATH,
VIDEO_TAGS_PATH,
TEST_TAGS_PATH,
5)
\ No newline at end of file
5)
'''
TestAll()
\ No newline at end of file
......