Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add train_test_indices file #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions train_test_indices.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# In the future we might need to define exact train and test sets to compare different models. This script has initiated for this purpose.

import os
import cv2

def load_images_from_folder(folder):
images = []
for filename in os.listdir(folder):
if filename.endswith(".png"):
img = cv2.imread(os.path.join(folder, filename))
if img is not None:
images.append(img)
return images
root_folder = '/home/sabrina/stinkbugs/labeled-data/'

directory_list = list()
for root, dirs, files in os.walk("/home/sabrina/stinkbugs/labeled-data", topdown=False):
for name in dirs:
directory_list.append(os.path.join(root, name))

folders = [os.path.join(root_folder, x) for x in directory_list]
all_images = [img for folder in folders for img in load_images_from_folder(folder)]
# %%
n_frames = len(all_images)
frames = list(range(0,n_frames))
random.Random(4).shuffle(frames)
split = 95
percent = int(split * len(frames) / 100)
train1 = frames[:percent]
test1 = frames[percent:]

list1 = deeplabcut.create_training_dataset(
config_path,
num_shuffles= suffle,
net_type="resnet_50",
augmenter_type="imgaug",
trainIndices = [train1],
testIndices = [test1],
)