Spaces:
Sleeping
Sleeping
Update Vit_Traning.py
Browse files- Vit_Traning.py +2 -17
Vit_Traning.py
CHANGED
@@ -9,21 +9,6 @@ import os
|
|
9 |
import pandas as pd
|
10 |
from sklearn.model_selection import train_test_split
|
11 |
|
12 |
-
def labeling(path_real, path_fake):
|
13 |
-
image_paths = []
|
14 |
-
labels = []
|
15 |
-
|
16 |
-
for filename in os.listdir(path_real):
|
17 |
-
image_paths.append(os.path.join(path_real, filename))
|
18 |
-
labels.append(0)
|
19 |
-
|
20 |
-
for filename in os.listdir(path_fake):
|
21 |
-
image_paths.append(os.path.join(path_fake, filename))
|
22 |
-
labels.append(1)
|
23 |
-
|
24 |
-
dataset = pd.DataFrame({'image_path': image_paths, 'label': labels})
|
25 |
-
|
26 |
-
return dataset
|
27 |
|
28 |
class CustomDataset(Dataset):
|
29 |
def __init__(self, dataframe, transform=None):
|
@@ -48,7 +33,7 @@ def shuffle_and_split_data(dataframe, test_size=0.2, random_state=59):
|
|
48 |
train_df, val_df = train_test_split(shuffled_df, test_size=test_size, random_state=random_state)
|
49 |
return train_df, val_df
|
50 |
|
51 |
-
class
|
52 |
def __init__(self):
|
53 |
# Check for GPU availability
|
54 |
self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
@@ -139,7 +124,7 @@ class CustomModel:
|
|
139 |
|
140 |
if __name__ == "__main__":
|
141 |
# Initialize the model
|
142 |
-
custom_model =
|
143 |
|
144 |
# Example usage: adding a new image and label
|
145 |
# custom_model.add_data('path/to/image.jpg', 0) # 0 for real, 1 for fake
|
|
|
9 |
import pandas as pd
|
10 |
from sklearn.model_selection import train_test_split
|
11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
class CustomDataset(Dataset):
|
14 |
def __init__(self, dataframe, transform=None):
|
|
|
33 |
train_df, val_df = train_test_split(shuffled_df, test_size=test_size, random_state=random_state)
|
34 |
return train_df, val_df
|
35 |
|
36 |
+
class Custom_VIT_Model:
|
37 |
def __init__(self):
|
38 |
# Check for GPU availability
|
39 |
self.device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
|
|
124 |
|
125 |
if __name__ == "__main__":
|
126 |
# Initialize the model
|
127 |
+
custom_model = Custom_VIT_Model()
|
128 |
|
129 |
# Example usage: adding a new image and label
|
130 |
# custom_model.add_data('path/to/image.jpg', 0) # 0 for real, 1 for fake
|