shivangibithel commited on
Commit
eccac7a
1 Parent(s): 087f23f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -8
app.py CHANGED
@@ -10,27 +10,35 @@ import pandas as pd
10
  import pickle
11
  import pickletools
12
  from transformers import AutoTokenizer, CLIPTextModelWithProjection
 
13
 
14
  # loading the train dataset
15
- # with open('clip_train.pkl', 'rb') as f:
16
- # temp_d = pickletools.dis(f)
17
  # train_xv = temp_d['image'].astype(np.float64) # Array of image features : np ndarray
18
  # train_xt = temp_d['text'].astype(np.float64) # Array of text features : np ndarray
19
  # train_yv = temp_d['label'] # Array of labels
20
- # train_yt = temp_d['label'] # Array of labels
21
  # ids = list(temp_d['ids']) # image names == len(images)
22
 
23
- train_yt = np.load("train_yt.npy")
24
 
25
  # loading the test dataset
26
- # with open('clip_test.pkl', 'rb') as f:
27
- # temp_d = pickletools.dis(f)
28
  # test_xv = temp_d['image'].astype(np.float64)
29
  # test_xt = temp_d['text'].astype(np.float64)
30
  # test_yv = temp_d['label']
31
- # test_yt = temp_d['label']
32
 
33
- test_xt = np.load("test_xt.npy")
 
 
 
 
 
 
 
34
 
35
  # Map the image ids to the corresponding image URLs
36
  image_map_name = 'pascal_dataset.csv'
 
10
  import pickle
11
  import pickletools
12
  from transformers import AutoTokenizer, CLIPTextModelWithProjection
13
+ from sklearn.preprocessing import normalize, OneHotEncoder
14
 
15
  # loading the train dataset
16
+ with open('clip_train.pkl', 'rb') as f:
17
+ temp_d = pickle.load(f)
18
  # train_xv = temp_d['image'].astype(np.float64) # Array of image features : np ndarray
19
  # train_xt = temp_d['text'].astype(np.float64) # Array of text features : np ndarray
20
  # train_yv = temp_d['label'] # Array of labels
21
+ train_yt = temp_d['label'] # Array of labels
22
  # ids = list(temp_d['ids']) # image names == len(images)
23
 
24
+ # train_yt = np.load("train_yt.npy")
25
 
26
  # loading the test dataset
27
+ with open('clip_test.pkl', 'rb') as f:
28
+ temp_d = pickle.load(f)
29
  # test_xv = temp_d['image'].astype(np.float64)
30
  # test_xt = temp_d['text'].astype(np.float64)
31
  # test_yv = temp_d['label']
32
+ test_yt = temp_d['label']
33
 
34
+ # test_xt = np.load("test_xt.npy")
35
+
36
+ enc = OneHotEncoder(sparse=False)
37
+ enc.fit(np.concatenate((train_yt, test_yt)).reshape((-1, 1)))
38
+ # train_yv = enc.transform(self.train_yv.reshape((-1, 1))).astype(np.float64)
39
+ # test_yv = enc.transform(self.test_yv.reshape((-1, 1))).astype(np.float64)
40
+ # train_yt = enc.transform(self.train_yt.reshape((-1, 1))).astype(np.float64)
41
+ test_yt = enc.transform(self.test_yt.reshape((-1, 1))).astype(np.float64)
42
 
43
  # Map the image ids to the corresponding image URLs
44
  image_map_name = 'pascal_dataset.csv'