Skip to content

Commit 2a07185

Browse files
ChongWei905ChongWei905
andauthored
fix: fix all zero initialized tensor problem for vit (#794)
Co-authored-by: ChongWei905 <weichong4@huawei.com>
1 parent 5c56e78 commit 2a07185

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

mindcv/models/vit.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,9 @@ def get_num_layers(self):
329329
def _init_weights(self):
330330
w = self.patch_embed.proj.weight
331331
w_shape_flatted = (w.shape[0], functools.reduce(lambda x, y: x*y, w.shape[1:]))
332-
w.set_data(initializer(XavierUniform(), w_shape_flatted, w.dtype).reshape(w.shape))
332+
w_value = initializer(XavierUniform(), w_shape_flatted, w.dtype)
333+
w_value.init_data()
334+
w.set_data(w_value.reshape(w.shape))
333335
for _, cell in self.cells_and_names():
334336
if isinstance(cell, nn.Dense):
335337
cell.weight.set_data(

0 commit comments

Comments
 (0)