I like to write Python code and and exploring new technology 😄
Currently learning about artificial intelligent, 3D image processing, web development🌱
tf.keras+Python Class 來實作CNN
License: MIT License
如題,目前計算FCN、UNet會出現梯度計算錯誤
TypeError: in user code:
e:\YJ\tf2-mycnn-main\mycnn\data\classification.py:189 None *
lambda x: load_img(x, "train")
e:\YJ\tf2-mycnn-main\mycnn\data\classification.py:134 load_img *
x = tf.cond(
C:\Anaconda3\envs\tf2\lib\site-packages\tensorflow\python\util\dispatch.py:201 wrapper **
return target(*args, **kwargs)
C:\Anaconda3\envs\tf2\lib\site-packages\tensorflow\python\ops\control_flow_ops.py:1396 cond_for_tf_v2
return cond(pred, true_fn=true_fn, false_fn=false_fn, strict=True, name=name)
C:\Anaconda3\envs\tf2\lib\site-packages\tensorflow\python\util\dispatch.py:201 wrapper
return target(*args, **kwargs)
C:\Anaconda3\envs\tf2\lib\site-packages\tensorflow\python\util\deprecation.py:538 new_func
return func(*args, **kwargs)
C:\Anaconda3\envs\tf2\lib\site-packages\tensorflow\python\ops\control_flow_ops.py:1180 cond
return cond_v2.cond_v2(pred, true_fn, false_fn, name)
C:\Anaconda3\envs\tf2\lib\site-packages\tensorflow\python\ops\cond_v2.py:99 cond_v2
return _build_cond(
C:\Anaconda3\envs\tf2\lib\site-packages\tensorflow\python\ops\cond_v2.py:257 _build_cond
_check_same_outputs(_COND, [true_graph, false_graph])
C:\Anaconda3\envs\tf2\lib\site-packages\tensorflow\python\ops\cond_v2.py:839 _check_same_outputs
error(b, "%s and %s have different types" % (b0_out, bn_out))
C:\Anaconda3\envs\tf2\lib\site-packages\tensorflow\python\ops\cond_v2.py:802 error
raise TypeError(
TypeError: true_fn and false_fn arguments to tf.cond must have the same number, type, and overall structure of return values.
true_fn output: Tensor("cond_4/Identity:0", shape=(227, 227, 3), dtype=float32)
false_fn output: Tensor("cond_4/Identity:0", shape=(227, 227, 3), dtype=uint8)
Error details:
Tensor("cond_4/Identity:0", shape=(227, 227, 3), dtype=float32) and Tensor("cond_4/Identity:0", shape=(227, 227, 3), dtype=uint8) have different types
可能會導致此結果 #17
包含升級CUDA、cudnn、tensorflow2
跟官方的 tf.data.Dataset
相比,分類模型準確度非常不好
ResourceExhaustedError Traceback (most recent call last)
<ipython-input-16-9898c6d2bce4> in <module>
----> 1 cnn.train_dataset(train_dataset, valid_dataset)
e:\YJ\tf2-mycnn\mycnn\core\_wrapper.py in wrapper(self, *args, **kwargs)
26 if not self.training and "training" in state:
27 raise NotImplementedError('Not define training parameter, please call `setup_training()` method.')
---> 28 return mth(self, *args, **kwargs)
29 return wrapper
30 return decorator
e:\YJ\tf2-mycnn\mycnn\core\base_model.py in train_dataset(self, tra_dataset, val_dataset, last_checkpoint)
307 epochs=self.__cfg['epochs'],
308 initial_epoch=self.__cfg['initial_epoch'],
--> 309 callbacks=self.__cbks_list)
310
311 @check_state("built")
C:\Anaconda3\envs\tf2\lib\site-packages\tensorflow\python\keras\engine\training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_batch_size, validation_freq, max_queue_size, workers, use_multiprocessing)
1098 _r=1):
1099 callbacks.on_train_batch_begin(step)
-> 1100 tmp_logs = self.train_function(iterator)
1101 if data_handler.should_sync:
1102 context.async_wait()
C:\Anaconda3\envs\tf2\lib\site-packages\tensorflow\python\eager\def_function.py in __call__(self, *args, **kwds)
826 tracing_count = self.experimental_get_tracing_count()
827 with trace.Trace(self._name) as tm:
--> 828 result = self._call(*args, **kwds)
829 compiler = "xla" if self._experimental_compile else "nonXla"
830 new_tracing_count = self.experimental_get_tracing_count()
C:\Anaconda3\envs\tf2\lib\site-packages\tensorflow\python\eager\def_function.py in _call(self, *args, **kwds)
853 # In this case we have created variables on the first call, so we run the
854 # defunned version which is guaranteed to never create variables.
--> 855 return self._stateless_fn(*args, **kwds) # pylint: disable=not-callable
856 elif self._stateful_fn is not None:
857 # Release the lock early so that multiple threads can perform the call
C:\Anaconda3\envs\tf2\lib\site-packages\tensorflow\python\eager\function.py in __call__(self, *args, **kwargs)
2941 filtered_flat_args) = self._maybe_define_function(args, kwargs)
2942 return graph_function._call_flat(
-> 2943 filtered_flat_args, captured_inputs=graph_function.captured_inputs) # pylint: disable=protected-access
2944
2945 @property
C:\Anaconda3\envs\tf2\lib\site-packages\tensorflow\python\eager\function.py in _call_flat(self, args, captured_inputs, cancellation_manager)
1917 # No tape is watching; skip to running the function.
1918 return self._build_call_outputs(self._inference_function.call(
-> 1919 ctx, args, cancellation_manager=cancellation_manager))
1920 forward_backward = self._select_forward_and_backward_functions(
1921 args,
C:\Anaconda3\envs\tf2\lib\site-packages\tensorflow\python\eager\function.py in call(self, ctx, args, cancellation_manager)
558 inputs=args,
559 attrs=attrs,
--> 560 ctx=ctx)
561 else:
562 outputs = execute.execute_with_cancellation(
C:\Anaconda3\envs\tf2\lib\site-packages\tensorflow\python\eager\execute.py in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
58 ctx.ensure_initialized()
59 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
---> 60 inputs, attrs, num_outputs)
61 except core._NotOkStatusException as e:
62 if name is not None:
ResourceExhaustedError: 2 root error(s) found.
(0) Resource exhausted: Failed to allocate memory for the batch of component 1
[[node IteratorGetNext (defined at e:\YJ\tf2-mycnn\mycnn\core\base_model.py:309) ]]
Hint: If you want to see a list of allocated tensors when OOM happens, add report_tensor_allocations_upon_oom to RunOptions for current allocation info.
(1) Resource exhausted: Failed to allocate memory for the batch of component 1
[[node IteratorGetNext (defined at e:\YJ\tf2-mycnn\mycnn\core\base_model.py:309) ]]
Hint: If you want to see a list of allocated tensors when OOM happens, add report_tensor_allocations_upon_oom to RunOptions for current allocation info.
[[IteratorGetNext/_7]]
Hint: If you want to see a list of allocated tensors when OOM happens, add report_tensor_allocations_upon_oom to RunOptions for current allocation info.
0 successful operations.
0 derived errors ignored. [Op:__inference_train_function_54100]
Function call stack:
train_function -> train_function
有關顏色的擴增資料感覺都沒變化
InvalidArgumentError: 2 root error(s) found.
(0) Invalid argument: Number of channels inherent in the image must be 1, 3 or 4, was 2
[[{{node decode_image/DecodeImage}}]]
[[IteratorGetNext]]
(1) Invalid argument: Number of channels inherent in the image must be 1, 3 or 4, was 2
[[{{node decode_image/DecodeImage}}]]
[[IteratorGetNext]]
[[IteratorGetNext/_4]]
0 successful operations.
0 derived errors ignored. [Op:__inference_train_function_1618]
Function call stack:
train_function -> train_function
failed to create cublas handle: CUBLAS_STATUS_ALLOC_FAILED
InvalidArgumentError: 2 root error(s) found.
(0) Invalid argument: Input size should match (header_size + row_size * abs_height) but they differ by 2
[[{{node decode_image/DecodeImage}}]]
[[IteratorGetNext]]
(1) Invalid argument: Input size should match (header_size + row_size * abs_height) but they differ by 2
[[{{node decode_image/DecodeImage}}]]
[[IteratorGetNext]]
[[IteratorGetNext/_2]]
0 successful operations.
0 derived errors ignored. [Op:__inference_train_function_1618]
Function call stack:
train_function -> train_function
InvalidArgumentError: 2 root error(s) found.
(0) Invalid argument: Unknown image file format. One of JPEG, PNG, GIF, BMP required.
[[{{node decode_image/DecodeImage}}]]
[[IteratorGetNext]]
[[IteratorGetNext/_2]]
(1) Invalid argument: Unknown image file format. One of JPEG, PNG, GIF, BMP required.
[[{{node decode_image/DecodeImage}}]]
[[IteratorGetNext]]
0 successful operations.
0 derived errors ignored. [Op:__inference_train_function_1618]
Function call stack:
train_function -> train_function
ValueError: in user code:
C:\Anaconda3\envs\tf2\lib\site-packages\tensorflow\python\keras\engine\training.py:805 train_function *
return step_function(self, iterator)
e:\YJ\tf2-mycnn\mycnn\losses\dice_loss.py:12 DiceLoss *
intersection = K.sum(K.dot(targets, inputs))
C:\Anaconda3\envs\tf2\lib\site-packages\tensorflow\python\util\dispatch.py:201 wrapper **
return target(*args, **kwargs)
C:\Anaconda3\envs\tf2\lib\site-packages\tensorflow\python\keras\backend.py:1898 dot
out = math_ops.matmul(x, y)
C:\Anaconda3\envs\tf2\lib\site-packages\tensorflow\python\util\dispatch.py:201 wrapper
return target(*args, **kwargs)
C:\Anaconda3\envs\tf2\lib\site-packages\tensorflow\python\ops\math_ops.py:3314 matmul
return gen_math_ops.mat_mul(
C:\Anaconda3\envs\tf2\lib\site-packages\tensorflow\python\ops\gen_math_ops.py:5547 mat_mul
_, _, _op, _outputs = _op_def_library._apply_op_helper(
C:\Anaconda3\envs\tf2\lib\site-packages\tensorflow\python\framework\op_def_library.py:748 _apply_op_helper
op = g._create_op_internal(op_type_name, inputs, dtypes=None,
C:\Anaconda3\envs\tf2\lib\site-packages\tensorflow\python\framework\func_graph.py:590 _create_op_internal
return super(FuncGraph, self)._create_op_internal( # pylint: disable=protected-access
C:\Anaconda3\envs\tf2\lib\site-packages\tensorflow\python\framework\ops.py:3528 _create_op_internal
ret = Operation(
C:\Anaconda3\envs\tf2\lib\site-packages\tensorflow\python\framework\ops.py:2015 __init__
self._c_op = _create_c_op(self._graph, node_def, inputs,
C:\Anaconda3\envs\tf2\lib\site-packages\tensorflow\python\framework\ops.py:1856 _create_c_op
raise ValueError(str(e))
ValueError: Shape must be rank 2 but is rank 1 for '{{node DiceLoss/MatMul}} = MatMul[T=DT_FLOAT, transpose_a=false, transpose_b=false](DiceLoss/Reshape_1, DiceLoss/Reshape)' with input shapes: [?], [?].
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.