-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLG.py
More file actions
56 lines (44 loc) · 1.2 KB
/
Copy pathLG.py
File metadata and controls
56 lines (44 loc) · 1.2 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
53
54
55
56
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from sklearn import linear_model
trainX = np.load('tinyX.npy') # this should have shape (26344, 3, 64, 64)
trainY = np.load('tinyY.npy')
testX = np.load('tinyX_test.npy')
print("Flattening...")
trainX_flattened = np.zeros((26344, 12288))
i = 0
for i in range(len(trainX)):
a = trainX[i].flatten()
trainX_flattened[i] = a
testX_flattened = np.zeros((len(testX), 12288))
j = 0
for i in range(len(testX)):
b = testX[j].flatten()
testX_flattened[j] = b
# to visualize only
# plt.imshow(trainX[18015].transpose(2, 1, 0))
# plt.show()
logistic = linear_model.LogisticRegression(verbose = 1)
print("Fitting data...")
logistic.fit(trainX_flattened, trainY)
print("Prediction testset...")
print(logistic.predict(testX_flattened))
# import cv2
#
# print('Read Image')
#
# img = cv2.imread('home.jpg')
# print('Convert to grayscale')
#
# gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# print('Create SIFT object')
#
# sift = cv2.xfeatures2d.SIFT_create()
# kp = sift.detect(gray, None)
# print('Draw Keypoints')
#
# img = cv2.drawKeypoints(gray, kp)
# print('Write picture with Keypoints to image')
#
# cv2.imwrite('sift_keypoints.jpg', img)