Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-2-capstone-design2
/
2015104208
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
이태현
2020-12-15 20:43:48 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
5e1c679487f79b7c6087605a5e7ab1f8f1157f63
5e1c6794
1 parent
1380ab57
func_edit2
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
120 additions
and
7 deletions
get-pip.py
test.txt
web/backend/yt8m/esot3ria/activation.py
web/backend/yt8m/esot3ria/video_recommender.py
get-pip.py
0 → 100644
View file @
5e1c679
This diff could not be displayed because it is too large.
test.txt
deleted
100644 → 0
View file @
1380ab5
결과
커널크기/비디오 수/캡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
web/backend/yt8m/esot3ria/activation.py
View file @
5e1c679
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
:
...
...
web/backend/yt8m/esot3ria/video_recommender.py
View file @
5e1c679
...
...
@@ -356,6 +356,93 @@ def test(tag_model_path, video_model_path, video_id_model, video_tags_path, segm
#===========
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,7 +451,7 @@ 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,
...
...
@@ -372,3 +459,6 @@ test(TAG_VECTOR_MODEL_PATH,
VIDEO_TAGS_PATH,
TEST_TAGS_PATH,
5)
'''
TestAll
()
\ No newline at end of file
...
...
Please
register
or
login
to post a comment