Object detection evaluation model main error - python

I'm currently working ona object detection model efficientnet and i tried to evaluate my mode with model main but got the error
ValueError: Tensor("Detections_Left_Groundtruth_Right/0:0", shape=(), dtype=string) must be from the same graph as Tensor("Loss/TargetAssignment/AvgNumGroundtruthBoxesPerImage:0", shape=(), dtype=string) (graphs are FuncGraph(name=cond_true_48273, id=139640549532432) and <tensorflow.python.framework.ops.Graph object at 0x7f0111ca0410>).
Can someone help me?

You can fix it by passing the checkpoint file path correctly, e.g.:
--checkpoint_dir=/checkpoint/ckpt-x, where x is the checkpoint number. Also check for this bug https://github.com/tensorflow/models/pull/5450. It worked for me.

Related

AttributeError: 'Adam' object has no attribute 'get_updates'

I'm training a VAE with TensorFlow Keras backend and I'm using Adam as the optimizer. the code I used is attached below.
def compile(self, learning_rate=0.0001):
optimizer = tf.keras.optimizers.Adam(learning_rate=learning_rate)
self.model.compile(optimizer=optimizer,
loss=self._calculate_combined_loss,
metrics=[_calculate_reconstruction_loss,
calculate_kl_loss(self)])
The TensorFlow version I'm using is 2.11.0. The error I'm getting is
AttributeError: 'Adam' object has no attribute 'get_updates'
I'm suspecting the issues arise because of the version mismatch. Can someone please help me to sort out the issue? Thanks in advance.

EagerTensor object has no attribute 'astype'

I am using trained tf model output (TF 2.8) and trying to convert it to numpy array.
trained_model = tf.keras.models.load_model(model_path)
output = trained_model(features)[index]
output.numpy()
But somehow in the process of converting the EagerTensor to Numpy array it tries to apply around function(I don't know why). And hence the following error arises:
/opt/conda/envs/my_env/lib/python3.8/site-packages/tensorflow/python/ops/numpy_ops/np_array_ops.py:738: in around
AttributeError: EagerTensor object has no attribute 'astype'.
E If you are looking for numpy-related methods, please run the following:
E from tensorflow.python.ops.numpy_ops import np_config
E np_config.enable_numpy_behavior()
What can I do here?
P.S. np_config.enable_numpy_behavior() doesn't work
UPD: Type of tensor : type: <dtype: 'float32'> <class 'tensorflow.python.framework.ops.EagerTensor'> tf.Tensor(78400.01, shape=(), dtype=float32)

Where does keras actually initialize the dataset?

I'm trying to figure out the implementation of SGD in tensorflow, especially how keras/tensorflow actually initializes and dispatches the dataset.
In the constructor (__init__ method) of class TensorLikeDataAdapter, self._dataset is initialized by this line
https://github.com/tensorflow/tensorflow/blob/r2.5/tensorflow/python/keras/engine/data_adapter.py#L346
self._dataset = dataset
I tried to print the value out with this line
print('enumerate_epochs self._dataset', list(self._dataset))
and I got
<_OptionsDataset shapes: ((None, 2), (None,)), types: (tf.float32, tf.float32)>
which seems to indicate that the dataset hasn't yet been actually loaded.
At the very begining of the enumerate_epochs method
https://github.com/tensorflow/tensorflow/blob/r2.5/tensorflow/python/keras/engine/data_adapter.py#L1196
I added this line
def enumerate_epochs(self):
print('enumerate_epochs self._dataset', list(self._dataset))
and I got 3 (I set epoch=3) of the actual dataset, which means the dataset has been initialized and randomized somewhere before.
I went through the whole data_adapter.py but failed to locate where the dataset is actually initialized.
highlight
I also tried this line
print('data_handler._dataset', data_handler._dataset)
for epoch, iterator in data_handler.enumerate_epochs():
and I got
data_handler._dataset <_OptionsDataset shapes: ((None, 2), (None,)), types: (tf.float32, tf.float32)>
However, this line
def _truncate_execution_to_epoch(self):
print('_truncate_execution_to_epoch self._dataset', list(self._dataset))
gives 3 (epoch=3) of the actual dataset, which means somewhere just in between the dataset is actually initialized though I couldn't imagine where it could be!
I also tried class DataHandler
print('DataHandler self._dataset', list(self._dataset))
self._configure_dataset_and_inferred_steps(strategy, x, steps_per_epoch,
class_weight, distribute)
and I got this error
AttributeError: 'DataHandler' object has no attribute '_dataset'
Could someone help me to see the light at the end of the tunnel.

The name 'Tensor' refers to a Tensor which does not exist. The operation, 'Tensor', does not exist in the graph

I know, this question has already been asked but none of the answers worked for me.
I'm trying to restore a model that I saved before. I used both the classical TF saver and the SavedModel. But the problem when loading remains the same. I get the error message as in the header:
"The name 'train_op:0' refers to a Tensor which does not exist. The operation, 'train_op', does not exist in the graph."
Well I get it that train_op is somehow not in the restored model graph but I don't know why.
I'm creating the train_op variable and assigning a name to it: train_op = optimizer.apply_gradients(grads_and_vars, global_step=global_step, name="train_op"). I'm saving the model using simple_save:
tf.saved_model.simple_save(sess,
model_file,
inputs={"x": X, "y": y},
outputs={"z": loss})
This is how I am loading the model:
tf.saved_model.loader.load(sess, [tf.saved_model.tag_constants.SERVING], model_file)
This is the line of code where the model appears:
_, summary = sess.run(["train_op:0", "summary_op:0"], feed_dict={"X-input:0": X_batch, "y-input:0": y_batch}, run_metadata=run_metadata)
I really don't understand the issue. I get the same problem for the other variables so it's not specific to train_op.
Thanks!

"tensor not found in the checkpoint" when evaluating the re-tuned inception-v3 model using TF-slim

When I evaluated the re-tuned inception-v3 model with my dataset using eval_image_classifier.py in TF-slim, I got an error:
NotFoundError (see above for traceback): Key InceptionV3/AuxLogits/Conv2d_2a_3x3/weights not found in checkpoint
[[Node: save/RestoreV2_7 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_save/Const_0_0, save/RestoreV2_7/tensor_names, save/RestoreV2_7/shape_and_slices)]]
Then I printed all tensors' names in the orignal inception-v3 checkpoint and the re-tuned checkpoint, then compared these tensors with tensors inception_v3.arg_scope, I found that some tensors in the checkpoint were different from that in the inception_v3.arg_scope:
"InceptionV3/AuxLogits/Conv2d_2a_3x3" in the inception_v3.arg_scope
"InceptionV3/AuxLogits/Conv2d_2a_5x5" in the checkpoints
Has the architecture of inception_v3 changed before? How to solve this problem? Retrain the whole inception-v3 model with inception_v3.arg_scope rather than re-tuning?
Add tf.reset_default_graph() to python script it will fix issue like this.

Categories

Resources