Predict w/ restored model from 'model.ckpt.data-00000-of-00001', 'model.ckpt.index', 'model.ckpt.meta'
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 15/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Cần làm rõ
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- python, tensorflow
- Lĩnh vực
- machine-learning
Hướng nghiên cứu
The issue asks how to restore a TensorFlow v1 checkpoint (model.ckpt.meta, .index, .data-00000-of-00001) and run inference, and it never names the input or output tensors. Start with the restore_ckpt function and the import_meta_graph call in the snippet, then inspect the graph to find the tensor names. Done means a documented way to load the EfficientNet-lite0 checkpoint and get predictions, which the thread has not yet settled.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Hello.
I tried to restore mobilenet model and efficientnet-lite which are not frozen model, so that I can use model to inference, retrain and/or transfer learning.
So I tried below using efficientnet-lite first.
import tensorflow.compat.v1 as tf
import os
import time
tf.compat.v1.disable_eager_execution()
def restore_ckpt(sess, model_dir, export_ckpt=None):
"""Restore variables from a given checkpoint.
Args:
sess: a tf session for restoring or exporting models.
ckpt_path: the path of the checkpoint. Can be a file path or a folder path.
export_ckpt: whether to export the restored model.
"""
files = os.listdir(model_dir)
if any(file for file in files if '.ckpt.' in file):
if tf.io.gfile.isdir(model_dir):
ckpt_path = tf.train.latest_checkpoint(model_dir)
for file in files:
if 'ckpt.meta' in file:
meta = file
meta_path = os.path.join(model_dir, meta)
saver = tf.train.import_meta_graph(meta_path)
# Restore all variables from ckpt.
start_time = time.time()
saver.restore(sess, ckpt_path)
end_time = time.time()
elapsed_time = end_time - start_time
print('Restoring model took {} seconds'.format(elapsed_time))
else:
raise ValueError("ckpt do not exist")
for img_idx, image in enumerate(image_list):
img = cv2.imread(input_dir + image)
# preprocessing
img = crop_image(img)
input_data = resize_img(img, input_details[0]['shape'][1], input_details[0]['shape'][2], interpolation)
input_data = preprocess_input(input_data, mode)
input_tensor = tf.convert_to_tensor(input_data)
ckpt_path = '/content/efficientnet-lite0/efficientnet-lite0/'
with tf.Session() as sess:
restore_ckpt(sess, ckpt_path, export_ckpt=None)
graph = tf.get_default_graph()
X = graph.get_tensor_by_name(INPUT_TENSOR_NAME)
y = graph.get_tensor_by_name(OUTPUT_TENSOR_NAME)
output_data = sess.run(y, feed_dict={X:input_data})
To execute 'sess.run()',as far as I know, input and output tensor name should be given.
I tried below to see the tensor name.
However, I do not know which one is INPUT_TENSOR_NAME, or OUPUT_TENSOR_NAME, because it is not a network I created .
all_tensors = [tensor for op in tf.get_default_graph().get_operations() for tensor in op.values()]
Then, I tried to use tensorboard, but the graph keeps disappearing
trained_checkpoint_prefix = '/content/efficientnet-lite0/efficientnet-lite0/model.ckpt'
export_dir = os.path.join('export_dir', '0')
!rm -rf {export_dir}
graph = tf.Graph()
with tf.compat.v1.Session(graph=graph) as sess:
# Restore from checkpoint
loader = tf.compat.v1.train.import_meta_graph(trained_checkpoint_prefix + '.meta')
loader.restore(sess, trained_checkpoint_prefix)
# Export checkpoint to SavedModel
builder = tf.compat.v1.saved_model.builder.SavedModelBuilder(export_dir)
builder.add_meta_graph_and_variables(sess,
[tf.compat.v1.saved_model.TRAINING, tf.compat.v1.saved_model.SERVING],
strip_default_attrs=True)
builder.save()
tf.enable_eager_execution()
%load_ext tensorboard
%tensorboard --logdir=./output/
Is there any other method to restore and run models from model.ckpt.data-00000-of-00001', 'model.ckpt.index', 'model.ckpt.meta' ?
- Ngôn ngữ chính
- Jupyter Notebook
- Star
- 5.3k
- Fork
- 1.7k
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của tensorflow/tpu
-
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 62/100
tensorflow/tpu#3542 ·
-
imagenet_to_gcs.pyĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
tensorflow/tpu#951 · 2 reaction ·
-
Broken linkĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 70/100
tensorflow/tpu#908 ·
-
Bug in imagenet_to_gcs.pyĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 62/100
tensorflow/tpu#889 · 1 bình luận · 1 reaction ·
-
Round filters Comment has typoĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
tensorflow/tpu#582 · 1 bình luận ·
Tất cả issue của tensorflow/tpu
Issue tương tự
-
needs-triage
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
flashinfer-ai/flashinfer#9803 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug module: rl
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
NVIDIA/Megatron-LM#9644 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
`build_flavor_config_from_local_checkpoint` fails with transformers 5.23.0: pipeline `impl` is now a dotted-path stringCó thể đã có người làm @mlflow-app đã nhận hôm nay. Đang mởhas-closing-pr nightly triage: reproduced
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
mlflow/mlflow#28000 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
X-PLUG/MobileAgent#304 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
FluxML/Optimisers.jl#254 ·