Skip to content

fixed reader bug and trainer bug #4904

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

Open
wants to merge 1 commit into
base: dev-static
Choose a base branch
from
Open
Show file tree
Hide file tree
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
14 changes: 7 additions & 7 deletions dygraph/tsn/compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
class TSN_UCF101_Dataset(Dataset):
def __init__(self, cfg, mode):
self.mode = mode
self.format = cfg.MODEL.format #'videos' or 'frames'
self.format = cfg.MODEL.format # 'videos' or 'frames'
self.seg_num = cfg.MODEL.seg_num
self.seglen = cfg.MODEL.seglen
self.short_size = cfg.TRAIN.short_size
self.target_size = cfg.TRAIN.target_size
self.short_size = cfg[mode.upper()]['short_size']
self.target_size = cfg[mode.upper()]['target_size']
self.img_mean = np.array(cfg.MODEL.image_mean).reshape(
[3, 1, 1]).astype(np.float32)
self.img_std = np.array(cfg.MODEL.image_std).reshape(
Expand All @@ -52,7 +52,7 @@ def _construct_loader(self):
if self.format == "videos":
path, label = path_label.split()
self._path_to_videos.append(path + '.avi')
self._num_frames.append(0) # unused
self._num_frames.append(0) # unused
self._labels.append(int(label))
elif self.format == "frames":
path, num_frames, label = path_label.split()
Expand Down Expand Up @@ -92,11 +92,11 @@ def __getitem__(self, idx):
format(path, ir))
return None, None
label = self._labels[idx]
return frames, np.array([label]) #, np.array([idx])
return frames, np.array([label]) # , np.array([idx])

def pipline(self, filepath, num_frames, format, seg_num, seglen, short_size,
target_size, img_mean, img_std, mode):
#Loader
# Loader
if format == 'videos':
Loader_ops = [
VideoDecoder(filepath), VideoSampler(seg_num, seglen, mode)
Expand All @@ -106,7 +106,7 @@ def pipline(self, filepath, num_frames, format, seg_num, seglen, short_size,
FrameLoader(filepath, num_frames, seg_num, seglen, mode)
]

#Augmentation
# Augmentation
if mode == 'train':
Aug_ops = [
Scale(short_size), RandomCrop(target_size), RandomFlip(),
Expand Down
28 changes: 18 additions & 10 deletions dygraph/tsn/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
import ast
import logging
import numpy as np
import paddle
import paddle.fluid as fluid
from paddle.fluid.dygraph.base import to_variable

from paddle.io import DataLoader, DistributedBatchSampler
from compose import TSN_UCF101_Dataset
from model import TSN_ResNet
from utils.config_utils import *
from reader.ucf101_reader import UCF101Reader

logging.root.handlers = []
FORMAT = '[%(levelname)s: %(filename)s: %(lineno)4d]: %(message)s'
Expand Down Expand Up @@ -68,21 +69,28 @@ def test(args):
model_dict, _ = fluid.load_dygraph(args.weights)
video_model.set_dict(model_dict)

test_reader = UCF101Reader(name="TSN", mode="test", cfg=test_config)
test_reader = test_reader.create_reader()
test_dataset = TSN_UCF101_Dataset(test_config, 'test')
test_sampler = DistributedBatchSampler(
test_dataset,
batch_size=test_config.VALID.batch_size,
shuffle=False,
drop_last=False)
test_loader = DataLoader(
test_dataset,
batch_sampler=test_sampler,
places=place,
num_workers=4,
return_list=True)

video_model.eval()
total_loss = 0.0
total_acc1 = 0.0
total_acc5 = 0.0
total_sample = 0

for batch_id, data in enumerate(test_reader()):
x_data = np.array([item[0] for item in data])
y_data = np.array([item[1] for item in data]).reshape([-1, 1])

imgs = to_variable(x_data)
labels = to_variable(y_data)
for batch_id, data in enumerate(test_loader):
imgs = paddle.to_tensor(data[0])
labels = paddle.to_tensor(data[1])
labels.stop_gradient = True
outputs = video_model(imgs)
loss = fluid.layers.cross_entropy(
Expand Down
Loading