Closed tanjiarui closed 2 years ago
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Hi there,
I got the index error when I try to fit the model on a simple data set
Traceback (most recent call last): File "/home/ubuntu/.local/lib/python3.8/site-packages/keras/utils/traceback_utils.py", line 67, in error_handler raise e.with_traceback(filtered_tb) from None File "/home/ubuntu/.local/lib/python3.8/site-packages/tensorflow/python/framework/func_graph.py", line 1147, in autograph_handler raise e.ag_error_metadata.to_exception(e) tensorflow.python.autograph.impl.api.StagingError: in user code File "/home/ubuntu/.local/lib/python3.8/site-packages/keras/engine/training.py", line 1021, in train_function * return step_function(self, iterator) File "/home/ubuntu/.local/lib/python3.8/site-packages/keras/engine/training.py", line 1010, in step_function ** outputs = model.distribute_strategy.run(run_step, args=(data,)) File "/home/ubuntu/.local/lib/python3.8/site-packages/keras/engine/training.py", line 1000, in run_step ** outputs = model.train_step(data) File "/home/ubuntu/.local/lib/python3.8/site-packages/keras/engine/training.py", line 859, in train_step y_pred = self(x, training=True) File "/home/ubuntu/.local/lib/python3.8/site-packages/keras/utils/traceback_utils.py", line 67, in error_handler raise e.with_traceback(filtered_tb) from None File "/home/ubuntu/桌面/face expression/fer/model/model.py", line 352, in call feature = self.bns[i][self.level](feature) IndexError: Exception encountered when calling layer "box_net" (type BoxNet). list index out of range Call arguments received: • inputs=['tf.Tensor(shape=(None, 64, 64, 64), dtype=float32)', 'tf.Tensor(shape=(), dtype=int32)'] • kwargs={'training': 'True'}
looks like the variable 'self.level' was over incremented to exceed the index range. this is the source code:
def call(self, inputs, **kwargs): feature, level = inputs for i in range(self.depth): feature = self.convs[i](feature) feature = self.bns[i][self.level](feature) feature = self.relu(feature) outputs = self.head(feature) outputs = self.reshape(outputs) self.level += 1 return outputs
this is the configuration of self.bns
self.bns = [[layers.BatchNormalization(momentum=MOMENTUM, epsilon=EPSILON, name=f'{self.name}/box-{i}-bn-{j}') for j in range(3, 8)] for i in range(depth)]
obviously, there are only 'depth' groups of batch layers, and five batch layers within each group. thus, that code snippet should be revised as follows:
def call(self, inputs, **kwargs): feature, level = inputs for i in range(self.depth): feature = self.convs[i](feature) feature = self.bns[i][self.level](feature) feature = self.relu(feature) outputs = self.head(feature) outputs = self.reshape(outputs) if self.level < 4: self.level += 1 else: self.level = 0 return outputs
Your answer is right, while I changed my code based on yours, it is more adaptive:
def call(self, inputs, **kwargs):
feature, level = inputs
for i in range(self.depth):
feature = self.convs[i](feature)
feature = self.bns[i][self.level](feature)
feature = self.relu(feature)
outputs = self.head(feature)
outputs = self.reshape(outputs)
if self.level < self.depth:
self.level += 1
else:
self.level = 0
return outputs
See Another Solution in the Closed Issue
BTW, the author does not seem to maintain the repo...
Hi there,
I got the index error when I try to fit the model on a simple data set
looks like the variable 'self.level' was over incremented to exceed the index range. this is the source code:
this is the configuration of self.bns
obviously, there are only 'depth' groups of batch layers, and five batch layers within each group. thus, that code snippet should be revised as follows: