Skip to content

pad input to use tensor core #4911

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

Merged
merged 1 commit into from
Oct 22, 2020
Merged
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
24 changes: 17 additions & 7 deletions PaddleCV/image_classification/dali.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def __init__(self,
num_shards=1,
random_shuffle=True,
num_threads=4,
seed=42):
seed=42,
pad_output=False):
super(HybridTrainPipe, self).__init__(
batch_size, num_threads, device_id, seed=seed)
self.input = ops.FileReader(
Expand Down Expand Up @@ -73,7 +74,8 @@ def __init__(self,
crop=(crop, crop),
image_type=types.RGB,
mean=mean,
std=std)
std=std,
pad_output=pad_output)
self.coin = ops.CoinFlip(probability=0.5)
self.to_int64 = ops.Cast(dtype=types.INT64, device="gpu")

Expand Down Expand Up @@ -104,7 +106,8 @@ def __init__(self,
num_shards=1,
random_shuffle=False,
num_threads=4,
seed=42):
seed=42,
pad_output=False):
super(HybridValPipe, self).__init__(
batch_size, num_threads, device_id, seed=seed)
self.input = ops.FileReader(
Expand All @@ -123,7 +126,8 @@ def __init__(self,
crop=(crop, crop),
image_type=types.RGB,
mean=mean,
std=std)
std=std,
pad_output=pad_output)
self.to_int64 = ops.Cast(dtype=types.INT64, device="gpu")

def define_graph(self):
Expand Down Expand Up @@ -169,6 +173,9 @@ def build(settings, mode='train'):
}
assert interp in interp_map, "interpolation method not supported by DALI"
interp = interp_map[interp]
pad_output = False
if settings.image_shape[0] == 4:
pad_output = True

if mode != 'train':
p = fluid.framework.cuda_places()[0]
Expand All @@ -188,7 +195,8 @@ def build(settings, mode='train'):
interp,
mean,
std,
device_id=device_id)
device_id=device_id,
pad_output=pad_output)
pipe.build()
return DALIGenericIterator(
pipe, ['feed_image', 'feed_label'],
Expand Down Expand Up @@ -221,7 +229,8 @@ def build(settings, mode='train'):
device_id,
shard_id,
num_shards,
seed=42 + shard_id)
seed=42 + shard_id,
pad_output=pad_output)
pipe.build()
pipelines = [pipe]
sample_per_shard = len(pipe) // num_shards
Expand All @@ -248,7 +257,8 @@ def build(settings, mode='train'):
device_id,
idx,
num_shards,
seed=42 + idx)
seed=42 + idx,
pad_output=pad_output)
pipe.build()
pipelines.append(pipe)
sample_per_shard = len(pipelines[0])
Expand Down
3 changes: 3 additions & 0 deletions PaddleCV/image_classification/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ def process_image(sample, settings, mode, color_jitter, rotate):
img_std = np.array(std).reshape((3, 1, 1))
img -= img_mean
img /= img_std
if settings.image_shape[0] == 4:
pad0 = np.zeros((1, img.shape[1], img.shape[2]))
img = np.concatenate((img, pad0), axis=0)
# doing training (train.py)
if mode == 'train' or (mode == 'val' and
not hasattr(settings, 'save_json_path')):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ python train.py \
--data_dir=${DATA_DIR} \
--batch_size=256 \
--total_images=1281167 \
--image_shape 3 224 224 \
--image_shape 4 224 224 \
--class_dim=1000 \
--print_step=10 \
--model_save_dir=output/ \
Expand Down