Skip to content

Commit 5e81f52

Browse files
ssheoreyCopilotbenjaminum
authored
Fix errors due to API change in Tensorflow 2.20 (#691)
Continued from copilot PR #690 - Fix SharedMLP.call in randlanet.py - make training keyword-only - Fix LocalSpatialEncoding.call in randlanet.py - make training and relative_features keyword-only - Fix AttentivePooling.call in randlanet.py - make training keyword-only - Fix LocalFeatureAggregation.call in randlanet.py - make training keyword-only - Fix BatchNormBlock.call call sites in network_blocks.py - pass training as keyword - Fix UnaryBlock.call in network_blocks.py - make batch and training keyword-only - Fix SimpleBlock.call in network_blocks.py - make batch keyword-only; fix internal training calls - Fix ResnetBottleneckBlock.call in network_blocks.py - make batch keyword-only; fix all internal training/batch calls - Fix NearestUpsampleBlock.call in network_blocks.py - make batch keyword-only - Fix KPFCNN.call in kpconv.py - pass batch as keyword in all block calls; fix head_mlp/head_softmax calls - Fix PointPillarsScatter.call in point_pillars.py - make batch_size keyword-only; fix call site in extract_feats - Fix tf_batch_neighbors in kpconv.py - pass radius, points_row_splits, queries_row_splits as keywords to FixedRadiusSearch - Fix SECONDFPN in point_pillars.py - add Permute layers to convert NCHW↔NHWC around Conv2DTranspose/Conv2D to avoid channels_first unsupported on CPU --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Benjamin Ummenhofer <benjamin.ummenhofer@intel.com>
1 parent 9fbddce commit 5e81f52

6 files changed

Lines changed: 39 additions & 32 deletions

File tree

ml3d/tf/models/kpconv.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,15 +293,15 @@ def call(self, flat_inputs, training=False):
293293
for block_i, block_op in enumerate(self.encoder_blocks):
294294
if block_i in self.encoder_skips:
295295
skip_conn.append(x)
296-
x = block_op(x, inputs, training=training)
296+
x = block_op(x, batch=inputs, training=training)
297297

298298
for block_i, block_op in enumerate(self.decoder_blocks):
299299
if block_i in self.decoder_concats:
300300
x = tf.concat([x, skip_conn.pop()], axis=1)
301-
x = block_op(x, inputs, training=training)
301+
x = block_op(x, batch=inputs, training=training)
302302

303-
x = self.head_mlp(x, inputs, training)
304-
x = self.head_softmax(x, inputs, training)
303+
x = self.head_mlp(x, batch=inputs, training=training)
304+
x = self.head_softmax(x, batch=inputs, training=training)
305305

306306
return x
307307

@@ -1049,7 +1049,11 @@ def tf_batch_neighbors(queries, points, q_batches, p_batches, r):
10491049
tf.concat([tf.constant([0]), tf.cumsum(q_batches)], axis=0), tf.int64)
10501050
p_splits = tf.cast(
10511051
tf.concat([tf.constant([0]), tf.cumsum(p_batches)], axis=0), tf.int64)
1052-
result = nns(points, queries, r, p_splits, q_splits)
1052+
result = nns(points,
1053+
queries,
1054+
radius=r,
1055+
points_row_splits=p_splits,
1056+
queries_row_splits=q_splits)
10531057

10541058
idx = result.neighbors_index
10551059
splits = result.neighbors_row_splits

ml3d/tf/models/network_blocks.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ def init_KP(self):
222222

223223
def regular_loss(self):
224224

225-
fitting_loss = 0
226-
repulsive_loss = 0
225+
fitting_loss = tf.constant(0.0)
226+
repulsive_loss = tf.constant(0.0)
227227

228228
if self.deformable:
229229
KP_min_d2 = self.min_d2 / (self.KP_extent**2)
@@ -432,7 +432,7 @@ def __init__(self, in_dim, use_bn, bn_momentum):
432432

433433
def call(self, x, training=False):
434434
if (self.use_bn):
435-
return self.batch_norm(x, training)
435+
return self.batch_norm(x, training=training)
436436
else:
437437
return x + self.bias
438438

@@ -470,9 +470,9 @@ def __init__(self,
470470
if not no_relu:
471471
self.leaky_relu = tf.keras.layers.LeakyReLU(l_relu)
472472

473-
def call(self, x, batch=None, training=False):
473+
def call(self, x, *, batch=None, training=False):
474474
x = self.mlp(x)
475-
x = self.batch_norm(x, training)
475+
x = self.batch_norm(x, training=training)
476476
if not self.no_relu:
477477
x = self.leaky_relu(x)
478478
return x
@@ -517,7 +517,7 @@ def __init__(self, block_name, in_dim, out_dim, radius, layer_ind, cfg):
517517
self.bn_momentum)
518518
self.leaky_relu = tf.keras.layers.LeakyReLU(cfg.get('l_relu', 0.2))
519519

520-
def call(self, x, batch, training=False):
520+
def call(self, x, *, batch, training=False):
521521

522522
# TODO : check x, batch
523523
if 'strided' in self.block_name:
@@ -530,7 +530,7 @@ def call(self, x, batch, training=False):
530530
neighb_inds = batch['neighbors'][self.layer_ind]
531531

532532
x = self.KPConv(q_pts, s_pts, neighb_inds, x)
533-
x = self.batch_norm(x, training)
533+
x = self.batch_norm(x, training=training)
534534
x = self.leaky_relu(x)
535535
return x
536536

@@ -621,7 +621,7 @@ def __init__(self, block_name, in_dim, out_dim, radius, layer_ind, cfg):
621621

622622
return
623623

624-
def call(self, features, batch, training=False):
624+
def call(self, features, *, batch, training=False):
625625

626626
if 'strided' in self.block_name:
627627
q_pts = batch['points'][self.layer_ind + 1]
@@ -633,21 +633,21 @@ def call(self, features, batch, training=False):
633633
neighb_inds = batch['neighbors'][self.layer_ind]
634634

635635
# First downscaling mlp
636-
x = self.unary1(features, training)
636+
x = self.unary1(features, training=training)
637637

638638
# Convolution
639639
x = self.KPConv(q_pts, s_pts, neighb_inds, x)
640-
x = self.leaky_relu(self.batch_norm_conv(x, training))
640+
x = self.leaky_relu(self.batch_norm_conv(x, training=training))
641641

642642
# Second upscaling mlp
643-
x = self.unary2(x, training)
643+
x = self.unary2(x, training=training)
644644

645645
# Shortcut
646646
if 'strided' in self.block_name:
647647
shortcut = max_pool(features, neighb_inds) # TODO : test max_pool
648648
else:
649649
shortcut = features
650-
shortcut = self.unary_shortcut(shortcut, training)
650+
shortcut = self.unary_shortcut(shortcut, training=training)
651651

652652
return self.leaky_relu(x + shortcut)
653653

@@ -664,7 +664,7 @@ def __init__(self, layer_ind):
664664
self.layer_ind = layer_ind
665665
return
666666

667-
def call(self, x, batch):
667+
def call(self, x, *, batch):
668668
return closest_pool(x, batch['upsamples'][self.layer_ind - 1])
669669

670670
def __repr__(self):

ml3d/tf/models/point_pillars.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ def extract_feats(self, points, training=False):
9696
coors,
9797
training=training)
9898

99-
batch_size = int(coors[-1, 0].numpy()) + 1
99+
batch_size = tf.cast(coors[-1, 0], tf.int32) + 1
100100

101101
x = self.middle_encoder(voxel_features,
102102
coors,
103-
batch_size,
103+
batch_size=batch_size,
104104
training=training)
105105
x = self.backbone(x, training=training)
106106
x = self.neck(x, training=training)
@@ -693,19 +693,19 @@ def __init__(self, in_channels=64, output_shape=[496, 432]):
693693
self.fp16_enabled = False
694694

695695
#@auto_fp16(apply_to=('voxel_features', ))
696-
def call(self, voxel_features, coors, batch_size, training=False):
696+
def call(self, voxel_features, coors, *, batch_size, training=False):
697697
"""Scatter features of single sample.
698698
699699
Args:
700700
voxel_features (tf.Tensor): Voxel features in shape (N, M, C).
701701
coors (tf.Tensor): Coordinates of each voxel in shape (N, 4).
702702
The first column indicates the sample ID.
703-
batch_size (int): Number of samples in the current batch.
703+
batch_size (int or tf.Tensor): Number of samples in the current batch.
704704
training (bool): Whether we are training or not?
705705
"""
706706
# batch_canvas will be the final output.
707707
batch_canvas = []
708-
for batch_itt in range(batch_size):
708+
for batch_itt in range(int(batch_size)):
709709
# Create the canvas for this sample
710710
canvas_shape = (self.nx * self.ny, self.in_channels)
711711

@@ -851,20 +851,22 @@ def __init__(self,
851851
kernel_size=upsample_strides[i],
852852
strides=upsample_strides[i],
853853
use_bias=False,
854-
data_format='channels_first',
854+
data_format='channels_last',
855855
)
856856
else:
857857
stride = np.round(1 / stride).astype(np.int64)
858-
upsample_layer = tf.keras.layers.Conv2D( # TODO : convert to channels last.
858+
upsample_layer = tf.keras.layers.Conv2D(
859859
filters=out_channels[i],
860860
kernel_size=stride,
861-
data_format='channels_first',
861+
data_format='channels_last',
862862
use_bias=False,
863863
strides=stride,
864864
kernel_initializer='he_normal')
865865

866866
deblock = tf.keras.Sequential()
867+
deblock.add(tf.keras.layers.Permute((2, 3, 1))) # NCHW -> NHWC
867868
deblock.add(upsample_layer)
869+
deblock.add(tf.keras.layers.Permute((3, 1, 2))) # NHWC -> NCHW
868870
deblock.add(
869871
tf.keras.layers.BatchNormalization(axis=1,
870872
epsilon=1e-3,

ml3d/tf/models/randlanet.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ def __init__(self,
536536
axis=-1, momentum=0.99, epsilon=1e-6) if bn else None
537537
self.activation_fn = activation_fn
538538

539-
def call(self, input, training):
539+
def call(self, input, *, training=None):
540540
"""Forward pass of the Module.
541541
542542
Args:
@@ -593,7 +593,8 @@ def call(self,
593593
coords,
594594
features,
595595
neighbor_indices,
596-
training,
596+
*,
597+
training=None,
597598
relative_features=None):
598599
"""Forward pass of the Module.
599600
@@ -654,7 +655,7 @@ def __init__(self, in_channels, out_channels):
654655
out_channels,
655656
activation_fn=tf.keras.layers.LeakyReLU(0.2))
656657

657-
def call(self, x, training):
658+
def call(self, x, *, training=None):
658659
"""Forward pass of the Module.
659660
660661
Args:
@@ -700,7 +701,7 @@ def __init__(self, d_in, d_out, num_neighbors):
700701
self.shortcut = SharedMLP(d_in, 2 * d_out)
701702
self.lrelu = tf.keras.layers.LeakyReLU(0.2)
702703

703-
def call(self, coords, feat, neighbor_indices, training):
704+
def call(self, coords, feat, neighbor_indices, *, training=None):
704705
"""Forward pass of the Module.
705706
706707
Args:

ml3d/tf/utils/tf_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def atoi(text):
77

88

99
def natural_keys(text):
10-
return [atoi(c) for c in re.split('(\d+)', text)]
10+
return [atoi(c) for c in re.split(r'(\d+)', text)]
1111

1212

1313
def gen_CNN(channels,

ml3d/torch/utils/torch_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def atoi(text):
99

1010

1111
def natural_keys(text):
12-
return [atoi(c) for c in re.split('(\d+)', text)]
12+
return [atoi(c) for c in re.split(r'(\d+)', text)]
1313

1414

1515
def latest_torch_ckpt(train_ckpt_dir):

0 commit comments

Comments
 (0)