-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdhashtrain.py
More file actions
52 lines (49 loc) · 1.18 KB
/
dhashtrain.py
File metadata and controls
52 lines (49 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from linearRegression import *
import itertools
import cv2
import os
import numpy as np
from support import *
from linearRegression import *
import random
from dhash import *
td1=[]
for i in ['wp','jp','bp']:
for j in os.listdir(i):
td1.append(i+'/'+j)
td1=random.sample(td1,len(td1))
td2=list(itertools.combinations(td1[:int(len(td1)/2)],2))
td3=list(itertools.combinations(td1[:-int(len(td1)/2)],2))
data=[]
for x in td2:
a=[]
p=int(dhash(cv2.imread(x[0]),2**5))
o=int(dhash(cv2.imread(x[1]),2**5))
for j in disstance(p,o,2**5):
a.append(int(j))
a.append(20 if x[0][:3]==x[1][:3] else 70)
#print(a)
data.append(a)
test=[]
for x in td3:
a=[]
p=int(dhash(cv2.imread(x[0]),2**5))
o=int(dhash(cv2.imread(x[1]),2**5))
for j in disstance(p,o,2**5):
a.append(int(j))
a.append(20 if x[0][:3]==x[1][:3] else 70)
#print(a)
data.append(a)
print(len(data))
print(len(test))
a=LinearRegression(data,'5005',1,False)
#a.var=list(np.load('004.npy'))
a.trainsimpleLR(250,0.000001,False,showdot=10)
a.save()
a.report()
i=0
for x in a.trainreport.val[-1].deatilrecord:
if x.abserror>(70-20)/2:
i+=1
#print(str(x))
print(i)