-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_data.py
More file actions
70 lines (64 loc) · 2.19 KB
/
Copy pathload_data.py
File metadata and controls
70 lines (64 loc) · 2.19 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
57
58
59
60
61
62
63
64
65
66
67
68
69
from sklearn.cluster import DBSCAN
from facenet_pytorch import MTCNN, InceptionResnetV1
from glob import glob
from getpass import getpass
from instaloader import ConnectionException, Instaloader, Profile
import instaloader
from os import mkdir, getcwd
import torch
from torch.utils.data import DataLoader
from torchvision import datasets, transforms
import numpy as np
import pandas as pd
import os
import scipy.misc
def loginUser(session):
L = session
USER = input("Username: ")
password = getpass()
try:
L.login(USER, password)
except InvalidArgumentException:
raise SystemExit("ERROR: Invalid username")
except BadCredentialsException:
raise SystemExit("ERROR: Invalid password")
except ConnectionException:
raise SystemExit("ERROR: Conneciton failed")
except TwoFactorAuthRequiredException:
print("TODO: Two factor Auth required, not implemented yet")
#Instaloader.two_factor_login()
def getProfilePosts(USERNAME):
#mkdir("training/" + USERNAME)
#save_path = 'training/' + USERNAME
profile = Profile.from_username(L.context, USERNAME)
save_target = USERNAME
for post in profile.get_posts():
#, target=save_target
if(not L.download_post(post)):
print("ERROR: Problem downloading post - Line 30")
def collate_fn(x):
return x[0]
def readFolder(dataset,folder):
dataset.idx_to_class = {i:c for c, i in dataset.class_to_idx.items()}
loader = DataLoader(dataset, collate_fn=collate_fn, num_workers=workers)
return loader
#MAIN
workers = 0 if os.name == 'nt' else 4
mtcnn = MTCNN(prewhiten=True, select_largest=True)
resnet = InceptionResnetV1(pretrained='vggface2').eval()
save_path = 'training/'
L = instaloader.Instaloader(dirname_pattern={profile})
loginUser(L)
cont = True
while(cont):
user = input('Enter username to download:')
getProfilePosts(user)
if (input("Continue? (y/n)") != 'y'): cont = False
#compute embeddings
#FIND distance matrix:
##dists = [[(e1 - average).norm().item() for e1 in embeddings]for e2 in embeddings]
##db = DBSCAN(eps=0.8).fit(dists)
##print("Labels: ")
##print(db.labels_)
##print("Core sample indices")
##print(db.core_sample_indices_)