当前,我正在尝试训练自动编码器,该编码器最初是从MNIST数据集中加载其数据的。但是,我正在尝试使用自己的自定义数据。当我使用以下代码将89 mb的数据加载到tensorflow中时:
def load_image(filename_tensor):
return tf.image.decode_jpeg(filename_tensor)
ds = tf.data.Dataset.list_files('./GradPhoto/*.jpg')
ds = ds.map(map_func=load_image)
mnist = ds
发生此错误:
---------------------------------------------------------------------------
InvalidArgumentError Traceback (most recent call last)
~\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py in _do_call(self, fn, *args)
1277 try:
-> 1278 return fn(*args)
1279 except errors.OpError as e:
~\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py in _run_fn(feed_dict, fetch_list, target_list, options, run_metadata)
1262 return self._call_tf_sessionrun(
-> 1263 options, feed_dict, fetch_list, target_list, run_metadata)
1264
~\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py in _call_tf_sessionrun(self, options, feed_dict, fetch_list, target_list, run_metadata)
1349 self._session, options, feed_dict, fetch_list, target_list,
-> 1350 run_metadata)
1351
InvalidArgumentError: Cannot parse tensor from proto: dtype: DT_FLOAT
tensor_shape {
dim {
size: 518400
}
dim {
size: 129600
}
}
float_val: 0
[[Node: Variable_1/Adam/Initializer/zeros = Const[_class=["loc:@Variable_1/Assign"], dtype=DT_FLOAT, value=<Invalid TensorProto: dtype: DT_FLOAT tensor_shape { dim { size: 518400 } dim { size: 129600 } } float_val: 0>, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
During handling of the above exception, another exception occurred:
InvalidArgumentError Traceback (most recent call last)
<ipython-input-31-8b742abdaf1d> in <module>
3
4 with tf.Session() as sess:
----> 5 sess.run(init)
6
7 # Epoch == Entire Training Set
~\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py in run(self, fetches, feed_dict, options, run_metadata)
875 try:
876 result = self._run(None, fetches, feed_dict, options_ptr,
--> 877 run_metadata_ptr)
878 if run_metadata:
879 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)
~\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
1098 if final_fetches or final_targets or (handle and feed_dict_tensor):
1099 results = self._do_run(handle, final_targets, final_fetches,
-> 1100 feed_dict_tensor, options, run_metadata)
1101 else:
1102 results = []
~\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py in _do_run(self, handle, target_list, fetch_list, feed_dict, options, run_metadata)
1270 if handle is None:
1271 return self._do_call(_run_fn, feeds, fetches, targets, options,
-> 1272 run_metadata)
1273 else:
1274 return self._do_call(_prun_fn, handle, feeds, fetches)
~\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\client\session.py in _do_call(self, fn, *args)
1289 except KeyError:
1290 pass
-> 1291 raise type(e)(node_def, op, message)
1292
1293 def _extend_graph(self):
InvalidArgumentError: Cannot parse tensor from proto: dtype: DT_FLOAT
tensor_shape {
dim {
size: 518400
}
dim {
size: 129600
}
}
float_val: 0
[[Node: Variable_1/Adam/Initializer/zeros = Const[_class=["loc:@Variable_1/Assign"], dtype=DT_FLOAT, value=<Invalid TensorProto: dtype: DT_FLOAT tensor_shape { dim { size: 518400 } dim { size: 129600 } } float_val: 0>, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
Caused by op 'Variable_1/Adam/Initializer/zeros', defined at:
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\ipykernel_launcher.py", line 16, in <module>
app.launch_new_instance()
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\traitlets\config\application.py", line 658, in launch_instance
app.start()
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\ipykernel\kernelapp.py", line 505, in start
self.io_loop.start()
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\tornado\platform\asyncio.py", line 148, in start
self.asyncio_loop.run_forever()
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\asyncio\base_events.py", line 438, in run_forever
self._run_once()
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\asyncio\base_events.py", line 1451, in _run_once
handle._run()
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\asyncio\events.py", line 145, in _run
self._callback(*self._args)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\tornado\ioloop.py", line 690, in <lambda>
lambda f: self._run_callback(functools.partial(callback, future))
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\tornado\ioloop.py", line 743, in _run_callback
ret = callback()
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\tornado\gen.py", line 781, in inner
self.run()
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\tornado\gen.py", line 742, in run
yielded = self.gen.send(value)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\ipykernel\kernelbase.py", line 357, in process_one
yield gen.maybe_future(dispatch(*args))
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\tornado\gen.py", line 209, in wrapper
yielded = next(result)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\ipykernel\kernelbase.py", line 267, in dispatch_shell
yield gen.maybe_future(handler(stream, idents, msg))
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\tornado\gen.py", line 209, in wrapper
yielded = next(result)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\ipykernel\kernelbase.py", line 534, in execute_request
user_expressions, allow_stdin,
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\tornado\gen.py", line 209, in wrapper
yielded = next(result)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\ipykernel\ipkernel.py", line 294, in do_execute
res = shell.run_cell(code, store_history=store_history, silent=silent)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\ipykernel\zmqshell.py", line 536, in run_cell
return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\IPython\core\interactiveshell.py", line 2848, in run_cell
raw_cell, store_history, silent, shell_futures)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\IPython\core\interactiveshell.py", line 2874, in _run_cell
return runner(coro)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\IPython\core\async_helpers.py", line 67, in _pseudo_sync_runner
coro.send(None)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\IPython\core\interactiveshell.py", line 3049, in run_cell_async
interactivity=interactivity, compiler=compiler, result=result)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\IPython\core\interactiveshell.py", line 3214, in run_ast_nodes
if (yield from self.run_code(code, result)):
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\IPython\core\interactiveshell.py", line 3296, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-26-ffd2f0e929af>", line 1, in <module>
train = optimizer.minimize(loss)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\training\optimizer.py", line 410, in minimize
name=name)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\training\optimizer.py", line 588, in apply_gradients
self._create_slots(var_list)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\training\adam.py", line 134, in _create_slots
self._zeros_slot(v, "m", self._name)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\training\optimizer.py", line 1134, in _zeros_slot
new_slot_variable = slot_creator.create_zeros_slot(var, op_name)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\training\slot_creator.py", line 181, in create_zeros_slot
colocate_with_primary=colocate_with_primary)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\training\slot_creator.py", line 155, in create_slot_with_initializer
dtype)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\training\slot_creator.py", line 65, in _create_slot_var
validate_shape=validate_shape)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 1467, in get_variable
aggregation=aggregation)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 1217, in get_variable
aggregation=aggregation)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 527, in get_variable
aggregation=aggregation)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 481, in _true_getter
aggregation=aggregation)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 903, in _get_single_variable
aggregation=aggregation)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 2443, in variable
aggregation=aggregation)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 2425, in <lambda>
previous_getter = lambda **kwargs: default_variable_creator(None, **kwargs)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 2406, in default_variable_creator
constraint=constraint)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\variables.py", line 259, in __init__
constraint=constraint)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\variables.py", line 368, in _init_from_args
initial_value(), name="initial_value", dtype=dtype)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\variable_scope.py", line 885, in <lambda>
shape.as_list(), dtype=dtype, partition_info=partition_info)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\init_ops.py", line 100, in __call__
return array_ops.zeros(shape, dtype)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\array_ops.py", line 1539, in zeros
output = _constant_if_small(zero, shape, dtype, name)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\ops\array_ops.py", line 1497, in _constant_if_small
return constant(value, shape=shape, dtype=dtype, name=name)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\constant_op.py", line 202, in constant
name=name).outputs[0]
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\util\deprecation.py", line 454, in new_func
return func(*args, **kwargs)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\ops.py", line 3155, in create_op
op_def=op_def)
File "C:\Users\Stanl\Miniconda3\envs\tensorflow\lib\site-packages\tensorflow\python\framework\ops.py", line 1717, in __init__
self._traceback = tf_stack.extract_stack()
InvalidArgumentError (see above for traceback): Cannot parse tensor from proto: dtype: DT_FLOAT
tensor_shape {
dim {
size: 518400
}
dim {
size: 129600
}
}
float_val: 0
[[Node: Variable_1/Adam/Initializer/zeros = Const[_class=["loc:@Variable_1/Assign"], dtype=DT_FLOAT, value=<Invalid TensorProto: dtype: DT_FLOAT tensor_shape { dim { size: 518400 } dim { size: 129600 } } float_val: 0>, _device="/job:localhost/replica:0/task:0/device:CPU:0"]()]]
我的张量小于2gb,所以我不明白为什么会这样。您能帮我修复我的代码吗?