Error while sequentially exporting two different inference graphs in tensorflow object detection API - tensorflow

I am using Tensorflow object detection API and I have trained two separate models( FRCNN Inception V2 and SSD Mobilenet V2). In my code flow, when both of the models have been trained, I need to export inference graphs. The following is the code for the same:
# Dependencies
import tensorflow as tf
import glob
import os
import re
from google.protobuf import text_format
from object_detection import exporter
from object_detection.protos import pipeline_pb2
class ExportInferenceGraph():
def __init__(self):
# input parameters for exporter
self.pipeline_config_path = None
self.trained_checkpoint_prefix = None
self.output_directory = None
#############################################################################
'''
code used form export_inference_graph.py file from Tensorflow github
'''
#############################################################################
flags = tf.app.flags
flags.DEFINE_string('input_type', 'image_tensor', 'Type of input node. Can be '
'one of [`image_tensor`, `encoded_image_string_tensor`, '
'`tf_example`]')
flags.DEFINE_string('input_shape', None,
'If input_type is `image_tensor`, this can explicitly set '
'the shape of this input tensor to a fixed size. The '
'dimensions are to be provided as a comma-separated list '
'of integers. A value of -1 can be used for unknown '
'dimensions. If not specified, for an `image_tensor, the '
'default shape will be partially specified as '
'`[None, None, None, 3]`.')
flags.DEFINE_string('config_override', '',
'pipeline_pb2.TrainEvalPipelineConfig '
'text proto to override pipeline_config_path.')
flags.DEFINE_boolean('write_inference_graph', False,
'If true, writes inference graph to disk.')
self.FLAGS = flags.FLAGS
#############################################################################
# method to get latest checkpoint files
def get_latest_checkpoints(self, trainingDir):
# getting list of all meta files
metaFiles = glob.glob(trainingDir + '/*.meta')
tempList = []
# sorting based on num_steps
for _file in metaFiles:
tempList.append(int(re.findall(r'[0-9]+', os.path.basename(_file))[0]))
tempList.sort(reverse = True)
# returning path of latest checkpoint file
return trainingDir + '/model.ckpt-' + str(tempList[0])
# parsing flags and exporting graphs
def export(self, pipeline_config_path, trained_checkpoint_dir, output_directory):
# path to store exported inference graphs
if not os.path.exists(output_directory):
os.makedirs(output_directory)
# getting latest checkpoint file
self.trained_checkpoint_prefix = self.get_latest_checkpoints(trained_checkpoint_dir)
print(self.trained_checkpoint_prefix)
self.pipeline_config_path = pipeline_config_path
self.output_directory = output_directory
#############################################################################
'''
code used form export_inference_graph.py file from Tensorflow
'''
#############################################################################
pipeline_config = pipeline_pb2.TrainEvalPipelineConfig()
with tf.gfile.GFile(self.pipeline_config_path, 'r') as f:
text_format.Merge(f.read(), pipeline_config)
text_format.Merge(self.FLAGS.config_override, pipeline_config)
if self.FLAGS.input_shape:
input_shape = [
int(dim) if dim != '-1' else None
for dim in self.FLAGS.input_shape.split(',')
]
else:
input_shape = None
exporter.export_inference_graph(
self.FLAGS.input_type, pipeline_config, self.trained_checkpoint_prefix,
self.output_directory, input_shape = input_shape,
write_inference_graph = self.FLAGS.write_inference_graph)
#############################################################################
This is the code snippet which shows how I call the methods for two different models:
export = ExportInferenceGraph()
export.export(pipeline_config_path = TRAIN_CONFIG_FILES[0],
trained_checkpoint_dir = MODEL_TRAIN_DIRS[0],
output_directory = INFERENCE_SUB_DIRS[0])
export.export(pipeline_config_path = TRAIN_CONFIG_FILES[1],
trained_checkpoint_dir = MODEL_TRAIN_DIRS[1],
output_directory = INFERENCE_SUB_DIRS[1])
But I am getting the following error:
2020-01-22 17:42:47.520891: W tensorflow/core/framework/op_kernel.cc:1502] OP_REQUIRES failed at save_restore_v2_ops.cc:184 : Not
found: Key BoxPredictor_0/BoxEncodingPredictor/biases not found in checkpoint
Traceback (most recent call last):
File "C:\Users\Lenovo\Anaconda3\envs\wsp\lib\site-packages\tensorflow\python\client\session.py", line 1356, in _do_call
return fn(*args)
File "C:\Users\Lenovo\Anaconda3\envs\wsp\lib\site-packages\tensorflow\python\client\session.py", line 1341, in _run_fn
options, feed_dict, fetch_list, target_list, run_metadata)
File "C:\Users\Lenovo\Anaconda3\envs\wsp\lib\site-packages\tensorflow\python\client\session.py", line 1429, in _call_tf_sessionrun
run_metadata)
tensorflow.python.framework.errors_impl.NotFoundError: Key BoxPredictor_0/BoxEncodingPredictor/biases not found in checkpoint
[[{{node save_1/RestoreV2}}]]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Lenovo\Anaconda3\envs\wsp\lib\site-packages\tensorflow\python\training\saver.py", line 1286, in restore
{self.saver_def.filename_tensor_name: save_path})
File "C:\Users\Lenovo\Anaconda3\envs\wsp\lib\site-packages\tensorflow\python\client\session.py", line 950, in run
run_metadata_ptr)
File "C:\Users\Lenovo\Anaconda3\envs\wsp\lib\site-packages\tensorflow\python\client\session.py", line 1173, in _run
feed_dict_tensor, options, run_metadata)
File "C:\Users\Lenovo\Anaconda3\envs\wsp\lib\site-packages\tensorflow\python\client\session.py", line 1350, in _do_run
run_metadata)
File "C:\Users\Lenovo\Anaconda3\envs\wsp\lib\site-packages\tensorflow\python\client\session.py", line 1370, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.NotFoundError: Key BoxPredictor_0/BoxEncodingPredictor/biases not found in checkpoint
[[node save_1/RestoreV2 (defined at ../TensorFlow/models/research\object_detection\exporter.py:323) ]]
Original stack trace for 'save_1/RestoreV2':
File "ocr_train.py", line 99, in <module>
output_directory = INFERENCE_SUB_DIRS[1])
File "D:\shubham\wsp\OCR\export_inference_graph.py", line 109, in export
write_inference_graph = self.FLAGS.write_inference_graph)
File "../TensorFlow/models/research\object_detection\exporter.py", line 489, in export_inference_graph
write_inference_graph=write_inference_graph)
File "../TensorFlow/models/research\object_detection\exporter.py", line 418, in _export_inference_graph
trained_checkpoint_prefix=checkpoint_to_use)
File "../TensorFlow/models/research\object_detection\exporter.py", line 323, in write_graph_and_checkpoint
tf.import_graph_def(inference_graph_def, name='')
File "C:\Users\Lenovo\Anaconda3\envs\wsp\lib\site-packages\tensorflow\python\util\deprecation.py", line 507, in new_func
return func(*args, **kwargs)
File "C:\Users\Lenovo\Anaconda3\envs\wsp\lib\site-packages\tensorflow\python\framework\importer.py", line 443, in import_graph_def
_ProcessNewOps(graph)
File "C:\Users\Lenovo\Anaconda3\envs\wsp\lib\site-packages\tensorflow\python\framework\importer.py", line 236, in _ProcessNewOps
for new_op in graph._add_new_tf_operations(compute_devices=False): # pylint: disable=protected-access
File "C:\Users\Lenovo\Anaconda3\envs\wsp\lib\site-packages\tensorflow\python\framework\ops.py", line 3751, in _add_new_tf_operations
for c_op in c_api_util.new_tf_operations(self)
File "C:\Users\Lenovo\Anaconda3\envs\wsp\lib\site-packages\tensorflow\python\framework\ops.py", line 3751, in <listcomp>
for c_op in c_api_util.new_tf_operations(self)
File "C:\Users\Lenovo\Anaconda3\envs\wsp\lib\site-packages\tensorflow\python\framework\ops.py", line 3641, in _create_op_from_tf_operation
ret = Operation(c_op, self)
File "C:\Users\Lenovo\Anaconda3\envs\wsp\lib\site-packages\tensorflow\python\framework\ops.py", line 2005, in __init__
self._traceback = tf_stack.extract_stack()
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Lenovo\Anaconda3\envs\wsp\lib\site-packages\tensorflow\python\training\saver.py", line 1296, in restore
names_to_keys = object_graph_key_mapping(save_path)
File "C:\Users\Lenovo\Anaconda3\envs\wsp\lib\site-packages\tensorflow\python\training\saver.py", line 1614, in object_graph_key_mapping
object_graph_string = reader.get_tensor(trackable.OBJECT_GRAPH_PROTO_KEY)
File "C:\Users\Lenovo\Anaconda3\envs\wsp\lib\site-packages\tensorflow\python\pywrap_tensorflow_internal.py", line 678, in get_tensor
return CheckpointReader_GetTensor(self, compat.as_bytes(tensor_str))
tensorflow.python.framework.errors_impl.NotFoundError: Key _CHECKPOINTABLE_OBJECT_GRAPH not found in checkpoint
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "ocr_train.py", line 99, in <module>
output_directory = INFERENCE_SUB_DIRS[1])
File "D:\shubham\wsp\OCR\export_inference_graph.py", line 109, in export
write_inference_graph = self.FLAGS.write_inference_graph)
File "../TensorFlow/models/research\object_detection\exporter.py", line 489, in export_inference_graph
write_inference_graph=write_inference_graph)
File "../TensorFlow/models/research\object_detection\exporter.py", line 418, in _export_inference_graph
trained_checkpoint_prefix=checkpoint_to_use)
File "../TensorFlow/models/research\object_detection\exporter.py", line 327, in write_graph_and_checkpoint
saver.restore(sess, trained_checkpoint_prefix)
File "C:\Users\Lenovo\Anaconda3\envs\wsp\lib\site-packages\tensorflow\python\training\saver.py", line 1302, in restore
err, "a Variable name or other graph key that is missing")
tensorflow.python.framework.errors_impl.NotFoundError: Restoring from checkpoint failed. This is most likely due to a Variable name or other graph key that is missing from the checkpoint. Please ensure that you have not altered the graph expected based on the
checkpoint. Original error:
Key BoxPredictor_0/BoxEncodingPredictor/biases not found in checkpoint
[[node save_1/RestoreV2 (defined at ../TensorFlow/models/research\object_detection\exporter.py:323) ]]
Original stack trace for 'save_1/RestoreV2':
File "ocr_train.py", line 99, in <module>
output_directory = INFERENCE_SUB_DIRS[1])
File "D:\shubham\wsp\OCR\export_inference_graph.py", line 109, in export
write_inference_graph = self.FLAGS.write_inference_graph)
File "../TensorFlow/models/research\object_detection\exporter.py", line 489, in export_inference_graph
write_inference_graph=write_inference_graph)
File "../TensorFlow/models/research\object_detection\exporter.py", line 418, in _export_inference_graph
trained_checkpoint_prefix=checkpoint_to_use)
File "../TensorFlow/models/research\object_detection\exporter.py", line 323, in write_graph_and_checkpoint
tf.import_graph_def(inference_graph_def, name='')
File "C:\Users\Lenovo\Anaconda3\envs\wsp\lib\site-packages\tensorflow\python\util\deprecation.py", line 507, in new_func
return func(*args, **kwargs)
File "C:\Users\Lenovo\Anaconda3\envs\wsp\lib\site-packages\tensorflow\python\framework\importer.py", line 443, in import_graph_def
_ProcessNewOps(graph)
File "C:\Users\Lenovo\Anaconda3\envs\wsp\lib\site-packages\tensorflow\python\framework\importer.py", line 236, in _ProcessNewOps
for new_op in graph._add_new_tf_operations(compute_devices=False): # pylint: disable=protected-access
File "C:\Users\Lenovo\Anaconda3\envs\wsp\lib\site-packages\tensorflow\python\framework\ops.py", line 3751, in _add_new_tf_operations
for c_op in c_api_util.new_tf_operations(self)
File "C:\Users\Lenovo\Anaconda3\envs\wsp\lib\site-packages\tensorflow\python\framework\ops.py", line 3751, in <listcomp>
for c_op in c_api_util.new_tf_operations(self)
File "C:\Users\Lenovo\Anaconda3\envs\wsp\lib\site-packages\tensorflow\python\framework\ops.py", line 3641, in _create_op_from_tf_operation
ret = Operation(c_op, self)
File "C:\Users\Lenovo\Anaconda3\envs\wsp\lib\site-packages\tensorflow\python\framework\ops.py", line 2005, in __init__
self._traceback = tf_stack.extract_stack()
NOTE: I could see the first graph exported successfully but it throws the error for the second graph. I interchanged calling of the export methods, it still failed at second export.
I am still new to Tensorflow and need some help here. I guess it is using the same graph which it created for the first model.

I dig deep into the Tensorflow directory and reached to method _export_inference_graph. The path is TensorFlow/models/research/object_detection/exporter.py. Adding this line at the end of the function solved my problem.
tf.reset_default_graph()

Related

Tensorflow restore() function throwing incompatible shape error

I am doing tensorflow source code modification, wherein I am modigying the call() function of the source code. Interestingly, the checkpoint restore() is giving the error of mismatch in shape.
But from my understanding the flow of code is: build()->restore()->call().
Although my change in tensorflow code is expected to alter shape in call phase, is it expected that restoring checkpoint which happens before it will give shape mismatch error? Or, there must be another reason for this error?
Traceback (most recent call last):
File "run_classifier.py", line 549, in <module>
app.run(main)
File "/home/arpitj/projects/lib/python3.8/site-packages/absl/app.py", line 300, in run
_run_main(main, args)
File "/home/arpitj/projects/lib/python3.8/site-packages/absl/app.py", line 251, in _run_main
sys.exit(main(argv))
File "run_classifier.py", line 542, in main
custom_main(custom_callbacks=None, custom_metrics=None)
File "run_classifier.py", line 485, in custom_main
checkpoint.restore(
File "/home/arpitj/projects/lib/python3.8/site-packages/tensorflow/python/training/tracking/util.py", line 2354, in restore
status = self.read(save_path, options=options)
File "/home/arpitj/projects/lib/python3.8/site-packages/tensorflow/python/training/tracking/util.py", line 2229, in read
result = self._saver.restore(save_path=save_path, options=options)
File "/home/arpitj/projects/lib/python3.8/site-packages/tensorflow/python/training/tracking/util.py", line 1366, in restore
base.CheckpointPosition(
File "/home/arpitj/projects/lib/python3.8/site-packages/tensorflow/python/training/tracking/base.py", line 254, in restore
restore_ops = trackable._restore_from_checkpoint_position(self) # pylint: disable=protected-access
File "/home/arpitj/projects/lib/python3.8/site-packages/tensorflow/python/training/tracking/base.py", line 983, in _restore_from_checkpoint_position
current_position.checkpoint.restore_saveables(
File "/home/arpitj/projects/lib/python3.8/site-packages/tensorflow/python/training/tracking/util.py", line 329, in restore_saveables
new_restore_ops = functional_saver.MultiDeviceSaver(
File "/home/arpitj/projects/lib/python3.8/site-packages/tensorflow/python/training/saving/functional_saver.py", line 339, in restore
restore_ops = restore_fn()
File "/home/arpitj/projects/lib/python3.8/site-packages/tensorflow/python/training/saving/functional_saver.py", line 323, in restore_fn
restore_ops.update(saver.restore(file_prefix, options))
File "/home/arpitj/projects/lib/python3.8/site-packages/tensorflow/python/training/saving/functional_saver.py", line 115, in restore
restore_ops[saveable.name] = saveable.restore(
File "/home/arpitj/projects/lib/python3.8/site-packages/tensorflow/python/training/saving/saveable_object_util.py", line 133, in restore
return resource_variable_ops.shape_safe_assign_variable_handle(
File "/home/arpitj/projects/lib/python3.8/site-packages/tensorflow/python/ops/resource_variable_ops.py", line 309, in shape_safe_assign_variable_handle
shape.assert_is_compatible_with(value_tensor.shape)
File "/home/arpitj/projects/lib/python3.8/site-packages/tensorflow/python/framework/tensor_shape.py", line 1171, in assert_is_compatible_with
raise ValueError("Shapes %s and %s are incompatible" % (self, other))
ValueError: Shapes (10, 64, 768) and (12, 64, 768) are incompatible

Reading keys from an .npz file with multiple workers in pytorch dataloader?

I have an .npz file where I have stored a dictionary. The dictionary has some keys and the values are numpy arrays. I want to read the dictionary in my getitem() method of the dataloader. When I set the dataloader num_workers to 1, everything runs fine. But when I increase the num workers, it throws the following error when reading the data from that npz file:
Traceback (most recent call last):
File "scripts/train.py", line 235, in <module>
train(args)
File "scripts/train.py", line 186, in train
solver(args.epoch, args.verbose)
File "/local-scratch/codebase/cap/lib/solver.py", line 174, in __call__
self._feed(self.dataloader["train"], "train", epoch_id)
File "/local-scratch/codebase/cap/lib/solver.py", line 366, in _feed
for data_dict in dataloader:
File "/local-scratch/anaconda3/envs/scanenv/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 819, in __next__
return self._process_data(data)
File "/local-scratch/anaconda3/envs/scanenv/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 846, in _process_data
data.reraise()
File "/local-scratch/anaconda3/envs/scanenv/lib/python3.6/site-packages/torch/_utils.py", line 369, in reraise
raise self.exc_type(msg)
zipfile.BadZipFile: Caught BadZipFile in DataLoader worker process 0.
Original Traceback (most recent call last):
File "/local-scratch/anaconda3/envs/scanenv/lib/python3.6/site-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop
data = fetcher.fetch(index)
File "/local-scratch/anaconda3/envs/scanenv/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 44, in fetch
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/local-scratch/anaconda3/envs/scanenv/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 44, in <listcomp>
data = [self.dataset[idx] for idx in possibly_batched_index]
File "/local-scratch/codebase/cap/lib/dataset.py", line 947, in __getitem__
other_bbox_feat = self.box_features['{}-{}_{}.{}'.format(scene_id, target_object_id, ann_id, object_id)]
File "/local-scratch/anaconda3/envs/scanenv/lib/python3.6/site-packages/numpy/lib/npyio.py", line 255, in __getitem__
pickle_kwargs=self.pickle_kwargs)
File "/local-scratch/anaconda3/envs/scanenv/lib/python3.6/site-packages/numpy/lib/format.py", line 763, in read_array
data = _read_bytes(fp, read_size, "array data")
File "/local-scratch/anaconda3/envs/scanenv/lib/python3.6/site-packages/numpy/lib/format.py", line 892, in _read_bytes
r = fp.read(size - len(data))
File "/local-scratch/anaconda3/envs/scanenv/lib/python3.6/zipfile.py", line 872, in read
data = self._read1(n)
File "/local-scratch/anaconda3/envs/scanenv/lib/python3.6/zipfile.py", line 962, in _read1
self._update_crc(data)
File "/local-scratch/anaconda3/envs/scanenv/lib/python3.6/zipfile.py", line 890, in _update_crc
raise BadZipFile("Bad CRC-32 for file %r" % self.name)
zipfile.BadZipFile: Bad CRC-32 for file 'scene0519_00-13_1.0.npy'
As far as I know, pytorch dataloader uses multiprocessing to for data loading. Perhaps the issue is with multiprocessing and .npz files. I really appreciate any help.

Saving a SavedModel: ValueError: At least two variables have the same name

I have a function that saves a SavedModel.
During training, this function is called from time to time, every N epochs, to replace the current SavedModel with a newer one.
def save_savedmodel(sess, snapshot_dir):
example = tf.get_collection("example")[0]
label = tf.get_collection("label")[0]
softmax = tf.get_collection("softmax")[0]
logits = tf.get_collection("logits")[0]
savedmodel_dir = snapshot_dir + "/saved_model"
shutil.rmtree(savedmodel_dir, ignore_errors=True)
tf.saved_model.simple_save(
sess,
savedmodel_dir,
inputs={"example": example},
outputs={"softmax": softmax, "logits": logits},
)
The script used to work, until I upgraded tensorflow to 1.12.
Now, the first time this function is called, it works, and subsequent calls result in the attached stacktrace, complaining that there are two variables named batch_normalization/beta/Adagrad:
ValueError: At least two variables have the same name:batch_normalization/beta/Adagrad
The first confusion is that this isn't true. This is what I see when I dump all of my variables just before calling simple_save()
for name in [n.name for n in tf.get_default_graph().as_graph_def().node]:
print(name)
batch_normalization/beta/Adagrad/Initializer/Const
batch_normalization/beta/Adagrad
batch_normalization/beta/Adagrad/Assign
batch_normalization/beta/Adagrad/read
batch_normalization/beta/Adagrad/Initializer/Const_1
batch_normalization/beta/Adagrad_1
batch_normalization/beta/Adagrad/Assign_1
batch_normalization/beta/Adagrad/read_1
There is batch_normalization/beta/Adagrad and batch_normalization/beta/Adagrad_1: is this normal or is this fishy?
What is confusing to me is that I am just saving the model. I am not restoring a model. So, is my graph already corrupted before I call this function a second time, or does saving a model modify the session in some way?
Pass your op to the equivalent parameter main_op instead.
Traceback (most recent call last):
File "src/tictactoe/train.py", line 412, in <module>
train(sess)
File "src/tictactoe/train.py", line 312, in train
write_snapshot(sess, saver, global_step_val, "champion")
File "src/tictactoe/train.py", line 185, in write_snapshot
save_savedmodel(sess, snapshot_dir)
File "src/tictactoe/train.py", line 209, in save_savedmodel
outputs={"softmax": softmax, "logits": logits},
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/saved_model/simple_save.py", line 85, in simple_save
clear_devices=True)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/util/deprecation.py", line 488, in new_func
return func(*args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/saved_model/builder_impl.py", line 415, in add_meta_graph_and_variables
saver = self._maybe_create_saver(saver)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/saved_model/builder_impl.py", line 272, in _maybe_create_saver
allow_empty=True)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py", line 1102, in __init__
self.build()
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py", line 1114, in build
self._build(self._filename, build_save=True, build_restore=True)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py", line 1151, in _build
build_save=build_save, build_restore=build_restore)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py", line 773, in _build_internal
saveables = self._ValidateAndSliceInputs(names_to_saveables)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py", line 673, in _ValidateAndSliceInputs
names_to_saveables = BaseSaverBuilder.OpListToDict(names_to_saveables)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/training/saver.py", line 572, in OpListToDict
name)
ValueError: At least two variables have the same name: batch_normalization/beta/Adagrad

type matching error in tensor

I am following a Tensorflow example. However, running the code gives me the following error message.
It seems to me that the following code segment causes the problem. Or the last dimension of h_conv10 has float64. But there is no place where float64 is setup explicitly. Thank you for the suggestions and hints.
# Deconvolution 1
W_deconv_1 = weight_variable_devonc([max_pool_size, max_pool_size, 8*chanel_root, 16*chanel_root])
b_deconv1 = bias_variable([8*chanel_root])
h_deconv1 = tf.nn.relu(deconv2d(h_conv10, W_deconv_1, max_pool_size) + b_deconv1)
h_deconv1_concat = crop_and_concat(h_conv8,h_deconv1,[n_image,(((nx-180)/2+4)/2+4)/2+4,(((ny-180)/2+4)/2+4)/2+4,8*chanel_root])
python u-net.py
Traceback (most recent call last):
File "/experiment/tfw/lib/python3.4/site-
packages/tensorflow/python/ops/op_def_library.py", line 377, in apply_op
as_ref=input_arg.is_ref)
File "/experiment/tfw/lib/python3.4/site-
packages/tensorflow/python/framework/ops.py", line 608, in convert_n_to_tensor
ret.append(convert_to_tensor(value, dtype=dtype, name=n, as_ref=as_ref))
File "/experiment/tfw/lib/python3.4/site-
packages/tensorflow/python/framework/ops.py", line 566, in convert_to_tensor
ret = conversion_func(value, dtype=dtype, name=name, as_ref=as_ref)
File "/experiment/tfw/lib/python3.4/site-
packages/tensorflow/python/framework/ops.py", line 510, in
_TensorTensorConversionFunction
% (dtype.name, t.dtype.name, str(t)))
ValueError: Tensor conversion requested dtype int32 for Tensor with dtype
float64: 'Tensor("truediv:0", shape=(), dtype=float64)'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "u-net.py", line 193, in <module>
h_deconv1 = tf.nn.relu(deconv2d(h_conv10, W_deconv_1, max_pool_size) + b_deconv1)
File "u-net.py", line 77, in deconv2d
output_shape = tf.pack([tf.shape(x)[0], tf.shape(x)[1]*2, tf.shape(x)[2]*2, tf.shape(x)[3]/2])
File "/experiment/tfw/lib/python3.4/site-packages/tensorflow/python/ops/array_ops.py", line 241, in pack
return gen_array_ops._pack(values, name=name)
File "/experiment/tfw/lib/python3.4/site-packages/tensorflow/python/ops/gen_array_ops.py", line 916, in _pack
return _op_def_lib.apply_op("Pack", values=values, name=name)
File "/experiment/tfw/lib/python3.4/site-packages/tensorflow/python/ops/op_def_library.py", line 396, in apply_op
raise TypeError("%s that don't all match." % prefix)
TypeError: Tensors in list passed to 'values' of 'Pack' Op have types [int32, int32, int32, float64] that don't all match.

How to see values inside tensor while using skflow

I've checked How to print the value of a Tensor object in TensorFlow?. However doesn't seem to be working out of the box with skflow.
E.g. tried like this :
with tf.Session():
word_vectors = skflow.ops.categorical_variable(X_test[0], n_classes=n_words,embedding_size=EMBEDDING_SIZE, name='words')
word_vectors.eval()
Also tried
sess = tf.InteractiveSession()
before calling word_vectors.eval(). But all this leads to crash:
Traceback (most recent call last):
File "/Users/mypc/Documents/scripts/scikitflow/small_rnn_test/test_load.py", line 32, in <module>
word_vectors.eval()
File "/Library/Python/2.7/site-packages/tensorflow/python/framework/ops.py", line 405, in eval
return _eval_using_default_session(self, feed_dict, self.graph, session)
File "/Library/Python/2.7/site-packages/tensorflow/python/framework/ops.py", line 2728, in _eval_using_default_session
return session.run(tensors, feed_dict)
File "/Library/Python/2.7/site-packages/tensorflow/python/client/session.py", line 345, in run
results = self._do_run(target_list, unique_fetch_targets, feed_dict_string)
File "/Library/Python/2.7/site-packages/tensorflow/python/client/session.py", line 419, in _do_run
e.code)
tensorflow.python.framework.errors.FailedPreconditionError: Attempting to use uninitialized value words/words_embeddings
[[Node: words/embedding_lookup/embedding_lookup = Gather[Tindices=DT_INT64, Tparams=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](words/words_embeddings, words/embedding_lookup/Reshape)]]
Caused by op u'words/embedding_lookup/embedding_lookup', defined at:
File "/Users/mypc/Documents/scripts/scikitflow/small_rnn_test/test_load.py", line 31, in <module>
word_vectors = skflow.ops.categorical_variable(X_test[0], n_classes=n_words,embedding_size=EMBEDDING_SIZE, name='words')
File "/Library/Python/2.7/site-packages/skflow/ops/embeddings_ops.py", line 77, in categorical_variable
return embedding_lookup(embeddings, tensor_in)
File "/Library/Python/2.7/site-packages/skflow/ops/embeddings_ops.py", line 50, in embedding_lookup
embeds_flat = tf.nn.embedding_lookup(params, ids_flat, name)
File "/Library/Python/2.7/site-packages/tensorflow/python/ops/embedding_ops.py", line 46, in embedding_lookup
return array_ops.gather(params[0], ids, name=name)
File "/Library/Python/2.7/site-packages/tensorflow/python/ops/gen_array_ops.py", line 302, in gather
name=name)
File "/Library/Python/2.7/site-packages/tensorflow/python/ops/op_def_library.py", line 633, in apply_op
op_def=op_def)
File "/Library/Python/2.7/site-packages/tensorflow/python/framework/ops.py", line 1710, in create_op
original_op=self._default_original_op, op_def=op_def)
File "/Library/Python/2.7/site-packages/tensorflow/python/framework/ops.py", line 988, in __init__
self._traceback = _extract_stack()
Does anybody know relatively easy way to look at content of Tensors created by skflow ?
It is not clear what error you are throwing but I got the error "Attempting to use uninitialized value words/words_embeddings". Initializing the variables fixed the error.
So the working code was:
word_vectors = skflow.ops.categorical_variable([1,2], n_classes=3,embedding_size=2, name='words')
with tf.Session() as sess:
tf.initialize_all_variables().run()
word_vectors.eval()
I have also moved the graph node word_vectors outside of the session context though that wasn't necessary to fix the error.
categorical_variable won't initialize all the variables for you. It's not like the estimators that initialize the session, variables, graph, etc. At this moment, if you use tf.initialize_all_variables().run(), you will be able to get those values. Also, note that you can access weights and biases via bias_ and weights_ properties of the estimators.