Skip to content
This repository has been archived by the owner on Nov 6, 2024. It is now read-only.

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
- Updated the model to a better one trained on 5 epochs
- logger makes things don't work so I removed it. Maybe the problem is that the logger search for a validation set that doesn't exists
- In the training generator I set use_graph = false in order to what has been said in a topic relative to the "not visible" keypoints
- Updated .gitignore
  • Loading branch information
Alberto Ursino committed Dec 8, 2020
1 parent f77ff4c commit 211d2ab
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 55 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,9 @@ tmp\.txt
tmp2\.txt

examples/deepposekit-data
alberto/deepposekit-data/datasets/zebra
alberto/deepposekit-data/datasets/locust
alberto/deepposekit-data/datasets/human
alberto/deepposekit-data/datasets/fly
alberto/deepposekit-data/datasets/gray.png
alberto/deepposekit-data/datasets/dog/dog_samples
2 changes: 1 addition & 1 deletion alberto/annotation/annotation_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def main():
randomly_sampled_frames = []
count = 0
for image_file in tqdm.tqdm(glob.glob(
'C:/Users/Alberto Ursino/Desktop/IntellIj Local Files/DeepPoseKit/alberto/deepposekit-data/datasets/dog/DAVIS/Annotations/Full-Resolution/dog/*.png')):
'C:/Users/Alberto Ursino/Desktop/IntellIj Local Files/DeepPoseKit/alberto/deepposekit-data/datasets/dog/dog_samples/*.png')):
count += 1
img = cv2.imread(image_file)
img = cv2.resize(img, IMAGE_SIZE)
Expand Down
49 changes: 22 additions & 27 deletions alberto/annotation/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,28 @@
IMAGE_SIZE = (512, 256)
TYPE = annotation_set.TYPE

# models = sorted(glob.glob(HOME + '/deepposekit-data/datasets/{}/log_densenet.h5'.format(TYPE)))
# model = load_model(HOME + '/deepposekit-data/datasets/{}/log_densenet.h5'.format(TYPE))
#
# randomly_sampled_frames = []
# count = 0
# for image_file in tqdm.tqdm(glob.glob(
# 'C:/Users/Alberto Ursino/Desktop/IntellIj Local Files/DeepPoseKit/alberto/deepposekit-data/datasets/dog/DAVIS/Annotations/Full-Resolution/dog/*.png')):
# count += 1
# img = cv2.imread(image_file)
# img = cv2.resize(img, IMAGE_SIZE)
# # img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# randomly_sampled_frames.append(img)
# img_channel = randomly_sampled_frames[0].shape[2]
#
# randomly_sampled_frames = np.concatenate(randomly_sampled_frames)
# randomly_sampled_frames = np.reshape(randomly_sampled_frames, (count, IMAGE_SIZE[1], IMAGE_SIZE[0], img_channel))
#
# predictions = model.predict(randomly_sampled_frames, verbose=1)
#
# np.save(HOME + '/deepposekit-data/datasets/{}/predictions.npy'.format(TYPE), predictions)

predictions = np.load(HOME + '/deepposekit-data/datasets/{}/predictions.npy'.format(TYPE))
models = sorted(glob.glob(HOME + '/deepposekit-data/datasets/{}/best_model_densenet.h5'.format(TYPE)))
model = load_model(HOME + '/deepposekit-data/datasets/{}/best_model_densenet.h5'.format(TYPE))

randomly_sampled_frames = []
count = 0
for image_file in tqdm.tqdm(glob.glob(
'C:/Users/Alberto Ursino/Desktop/IntellIj Local Files/DeepPoseKit/alberto/deepposekit-data/datasets/dog/DAVIS/Annotations/Full-Resolution/dog/*.png')):
count += 1
img = cv2.imread(image_file)
img = cv2.resize(img, IMAGE_SIZE)
# img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
randomly_sampled_frames.append(img)
img_channel = randomly_sampled_frames[0].shape[2]

randomly_sampled_frames = np.concatenate(randomly_sampled_frames)
randomly_sampled_frames = np.reshape(randomly_sampled_frames, (count, IMAGE_SIZE[1], IMAGE_SIZE[0], img_channel))

predictions = model.predict(randomly_sampled_frames, verbose=1)

np.save(HOME + '/deepposekit-data/datasets/{}/predictions.npy'.format(TYPE), predictions)

# predictions = np.load(HOME + '/deepposekit-data/datasets/{}/predictions.npy'.format(TYPE))

x, y, confidence = np.split(predictions, 3, -1)

Expand All @@ -66,8 +66,3 @@
s=50, cmap=plt.cm.hsv, zorder=3)

plt.show()

plt.scatter(keypoints[0, :, 0], keypoints[0, :, 1], c=np.arange(data_generator.keypoints_shape[0]), s=50,
cmap=plt.cm.hsv, zorder=3)

plt.show()
57 changes: 30 additions & 27 deletions alberto/annotation/train.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
from alberto.annotation import annotation_set
from pandas import np

from deepposekit.io import TrainingGenerator, DataGenerator
from deepposekit.augment import FlipAxis
import imgaug.augmenters as iaa
import imgaug as ia

from deepposekit.models import StackedHourglass
from deepposekit.models import load_model
import matplotlib.pyplot as plt

from tensorflow.keras.callbacks import ReduceLROnPlateau, EarlyStopping

Expand All @@ -21,26 +24,26 @@
data_generator = DataGenerator(
datapath=HOME + '/deepposekit-data/datasets/{}/annotation_set_{}_{}.h5'.format(TYPE, IMAGE_SIZE[0], IMAGE_SIZE[1]))

# image, keypoints = data_generator[0]
#
# plt.figure(figsize=(5, 5))
# image = image[0] if image.shape[-1] is 3 else image[0, ..., 0]
# cmap = None if image.shape[-1] is 3 else 'gray'
# plt.imshow(image, cmap=cmap, interpolation='none')
# for idx, jdx in enumerate(data_generator.graph):
# if jdx > -1:
# x1 = keypoints[0, idx, 0]
# x2 = keypoints[0, jdx, 0]
# if (0 <= x1 <= IMAGE_SIZE[0]) and (0 <= x2 <= IMAGE_SIZE[0]):
# plt.plot(
# [keypoints[0, idx, 0], keypoints[0, jdx, 0]],
# [keypoints[0, idx, 1], keypoints[0, jdx, 1]],
# 'r-'
# )
image, keypoints = data_generator[0]

# plt.scatter(keypoints[0, :, 0], keypoints[0, :, 1], c=np.arange(data_generator.keypoints_shape[0]), s=50, cmap=plt.cm.hsv, zorder=3)
plt.figure(figsize=(5, 5))
image = image[0] if image.shape[-1] is 3 else image[0, ..., 0]
cmap = None if image.shape[-1] is 3 else 'gray'
plt.imshow(image, cmap=cmap, interpolation='none')
for idx, jdx in enumerate(data_generator.graph):
if jdx > -1:
x1 = keypoints[0, idx, 0]
x2 = keypoints[0, jdx, 0]
if (0 <= x1 <= IMAGE_SIZE[0]) and (0 <= x2 <= IMAGE_SIZE[0]):
plt.plot(
[keypoints[0, idx, 0], keypoints[0, jdx, 0]],
[keypoints[0, idx, 1], keypoints[0, jdx, 1]],
'r-'
)

# plt.show()
#plt.scatter(keypoints[0, :, 0], keypoints[0, :, 1], c=np.arange(data_generator.keypoints_shape[0]), s=50, cmap=plt.cm.hsv, zorder=3)

plt.show()

# Augmentation

Expand Down Expand Up @@ -87,7 +90,7 @@
# 'r-'
# )

# plt.scatter(keypoints[0, :, 0], keypoints[0, :, 1], c=np.arange(data_generator.keypoints_shape[0]), s=50, cmap=plt.cm.hsv, zorder=3)
plt.scatter(keypoints[0, :, 0], keypoints[0, :, 1], c=np.arange(data_generator.keypoints_shape[0]), s=50, cmap=plt.cm.hsv, zorder=3)

# plt.show()

Expand All @@ -96,7 +99,7 @@
augmenter=augmenter,
sigma=5,
validation_split=0,
use_graph=True,
use_graph=False,
random_seed=1,
graph_scale=1)
train_generator.get_config()
Expand Down Expand Up @@ -136,10 +139,10 @@
# t1 = time.time()
# print(x.shape[0] / (t1 - t0))

logger = Logger(validation_batch_size=10,
# filepath saves the logger data to a .h5 file
filepath=HOME + "/deepposekit-data/datasets/{}/log_densenet.h5".format(TYPE)
)
# logger = Logger(validation_batch_size=10,
# # filepath saves the logger data to a .h5 file
# filepath=HOME + "/deepposekit-data/datasets/{}/log_densenet.h5".format(TYPE)
# )

# Remember, if you set validation_split=0 for your TrainingGenerator,
# which will just use the training set for model fitting,
Expand All @@ -162,7 +165,7 @@
verbose=1
)

callbacks = [early_stop, reduce_lr, model_checkpoint, logger]
callbacks = [early_stop, reduce_lr, model_checkpoint]

model.fit(
batch_size=1,
Expand All @@ -175,11 +178,11 @@
)

# model = load_model(
# HOME + "/deepposekit-data/datasets/{}/log_densenet.h5".format(TYPE),
# HOME + "/deepposekit-data/datasets/{}/best_model_densenet.h5".format(TYPE),
# augmenter=augmenter,
# generator=data_generator,
# )
#

# model.fit(
# batch_size=5,
# validation_batch_size=10,
Expand Down
Binary file modified alberto/deepposekit-data/datasets/dog/best_model_densenet.h5
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 211d2ab

Please sign in to comment.