Predict w/ restored model from 'model.ckpt.data-00000-of-00001', 'model.ckpt.index', 'model.ckpt.meta'
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 15/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Da chiarire
- Stato di attività
- Ferma
- Stack tecnologico
- python, tensorflow
- Ambito
- machine-learning
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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' ?
- Lingua principale
- Jupyter Notebook
- Stelle
- 5.3k
- Fork
- 1.7k
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di tensorflow/tpu
-
Difficoltà 2/5 Mezza giornata Idoneità per principianti 62/100
tensorflow/tpu#3542 ·
-
imagenet_to_gcs.pyAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
tensorflow/tpu#951 · 2 reazioni ·
-
Broken linkAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 70/100
tensorflow/tpu#908 ·
-
Bug in imagenet_to_gcs.pyAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 62/100
tensorflow/tpu#889 · 1 commento · 1 reazione ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
tensorflow/tpu#582 · 1 commento ·
Tutte le issue di tensorflow/tpu
Issue simili
-
needs-triage
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
flashinfer-ai/flashinfer#9803 ·
I maintainer di solito rispondono entro 1 giorno
-
bug module: rl
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
NVIDIA/Megatron-LM#9644 ·
I maintainer di solito rispondono entro 2 giorni
-
`build_flavor_config_from_local_checkpoint` fails with transformers 5.23.0: pipeline `impl` is now a dotted-path stringForse già presa @mlflow-app l’ha presa oggi. Apertahas-closing-pr nightly triage: reproduced
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
mlflow/mlflow#28000 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
X-PLUG/MobileAgent#304 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
FluxML/Optimisers.jl#254 ·