tensorflow / tensorflow/models
ValueError: Checkpoint was expecting to be a trackable object (an object derived from Trackable)
Open
@laxmareddyp is already working on this.
Since Jul 7, 2023.
models:research
type:bug
- Dominant language
- Python
- Stars
- 77.7k
- Forks
- 44.8k
- PR merge metrics
- No merged PRs in 30d
Description
Issue type
Bug
TensorFlow version
tf 2.10.0
Custom code
Yes
OS platform and distribution
Windows 10 Enterprise
Python version
3.9.16
Current behavior?
I'm receiving an error when I try to restore the model checkpoint. I've seen a posting on here that's similar, but I think my case is different. Help is very much appreciated!
I'm using a pre-trained object detection model called SSD MobileNet V2 FPNLite 320x320
Standalone code to reproduce the issue
import os
import tensorflow as tf
import pandas as pd
import openpyxl
import cv2
import numpy as np
from object_detection.utils import label_map_util
from object_detection.utils import visualization_utils as viz_utils
from object_detection.builders import model_builder
from object_detection.utils import config_util
from matplotlib import pyplot as plt
from pathlib import Path
os.chdir(r"C:\Users\mill286")
CUSTOM_MODEL_NAME = 'my_ssd_resnet50_v1_fpn' # *** Enter here the name of the model you trained. ***
files = {
'PIPELINE_CONFIG':os.path.join('tensorflow', 'workspace','models', CUSTOM_MODEL_NAME, 'pipeline.config')
}
# Load pipeline config and build a detection model
configs = config_util.get_configs_from_pipeline_file(files['PIPELINE_CONFIG'])
detection_model = model_builder.build(model_config=configs['model'], is_training=False)
# Restore checkpoint
ckpt = tf.compat.v2.train.Checkpoint(model=detection_model)
ckpt.restore(os.path.join(paths['CHECKPOINT_PATH'], 'ckpt-54.index')).expect_partial() # *** Replace the number in 'ckpt-XX' with the checkpoint you want to use. ***
Relevant log output
ValueError Traceback (most recent call last)
Cell In[18], line 2
1 # Restore checkpoint
----> 2 ckpt = tf.compat.v2.train.Checkpoint(model=detection_model)
3 ckpt.restore(os.path.join(paths['CHECKPOINT_PATH'], 'ckpt-54.index')).expect_partial()
File ~\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\checkpoint\checkpoint.py:2142, in Checkpoint.__init__(self, root, **kwargs)
2140 if isinstance(converted_v, weakref.ref):
2141 converted_v = converted_v()
-> 2142 _assert_trackable(converted_v, k)
2144 if root:
2145 # Make sure that root doesn't already have dependencies with these names
2146 child = trackable_root._lookup_dependency(k)
File ~\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow\python\checkpoint\checkpoint.py:1562, in _assert_trackable(obj, name)
1559 def _assert_trackable(obj, name):
1560 if not isinstance(
1561 obj, (base.Trackable, def_function.Function)):
-> 1562 raise ValueError(
1563 f"`Checkpoint` was expecting {name} to be a trackable object (an "
1564 f"object derived from `Trackable`), got {obj}. If you believe this "
1565 "object should be trackable (i.e. it is part of the "
1566 "TensorFlow Python API and manages state), please open an issue.")
ValueError: `Checkpoint` was expecting model to be a trackable object (an object derived from `Trackable`), got <object_detection.meta_architectures.ssd_meta_arch.SSDMetaArch object at 0x000001E163D93910>. If you believe this object should be trackable (i.e. it is part of the TensorFlow Python API and manages state), please open an issue.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.