mokeam / Chinese-Word-Segmentation-in-NLP

State of the art Chinese Word Segmentation with Bi-LSTMs
28 stars 6 forks source link

can you write more details about predict.py, what files needed? i got trouble when predict, training is OK #3

Closed rxc205 closed 4 years ago

mokeam commented 4 years ago

Run: python3 predict.py input_path output_path resources_path

Exactly what was described in the README. What errors are you having?

rxc205 commented 4 years ago

**### Q1:** 2020-01-08 14:53:39.963066: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1326] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 1992 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:86:00.0, compute capability: 6.1) 2020-01-08 14:53:39.967101: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x64a3b70 executing computations on platform CUDA. Devices: 2020-01-08 14:53:39.967139: I tensorflow/compiler/xla/service/service.cc:175] StreamExecutor device (0): GeForce GTX 1080 Ti, Compute Capability 6.1 2020-01-08 14:53:41.875941: W tensorflow/core/framework/allocator.cc:107] Allocation of 512000000 exceeds 10% of system memory. 2020-01-08 14:53:42.320094: W tensorflow/core/framework/allocator.cc:107] Allocation of 512000000 exceeds 10% of system memory. Traceback (most recent call last): File "//anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1356, in _do_call return fn(*args) File "//anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1339, in _run_fn self._extend_graph() File "//anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1374, in _extend_graph tf_session.ExtendSession(self._session) tensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot assign a device for operation embedding/embeddings/Initializer/random_uniform/sub: Could not satisfy explicit device specification '' because the node {{colocation_node embedding/embeddings/Initializer/random_uniform/sub}} was colocated with a group of nodes that required incompatible device '/job:localhost/replica:0/task:0/device:GPU:0'. All available devices [/job:localhost/replica:0/task:0/device:CPU:0, /job:localhost/replica:0/task:0/device:XLA_CPU:0, /job:localhost/replica:0/task:0/device:GPU:0, /job:localhost/replica:0/task:0/device:XLA_GPU:0]. Colocation Debug Info: Colocation group had the following types and supported devices: Root Member(assigned_device_nameindex=1 requested_devicename='/job:localhost/replica:0/task:0/device:GPU:0' assigned_devicename='/job:localhost/replica:0/task:0/device:GPU:0' resource_devicename='/job:localhost/replica:0/task:0/device:GPU:0' supported_devicetypes=[CPU] possibledevices=[] ResourceSparseApplyKerasMomentum: CPU Sub: GPU CPU XLA_CPU XLA_GPU Add: GPU CPU XLA_CPU XLA_GPU Fill: GPU CPU XLA_CPU XLA_GPU Mul: GPU CPU XLA_CPU XLA_GPU Const: GPU CPU XLA_CPU XLA_GPU RandomUniform: GPU CPU XLA_CPU XLA_GPU ReadVariableOp: GPU CPU XLA_CPU XLA_GPU VarIsInitializedOp: GPU CPU XLA_CPU XLA_GPU VarHandleOp: GPU CPU XLA_CPU XLA_GPU AssignVariableOp: GPU CPU XLA_CPU XLA_GPU ResourceGather: GPU CPU XLA_CPU XLA_GPU Identity: GPU CPU XLA_CPU XLA_GPU

Colocation members, user-requested devices, and framework assigned devices, if any: embedding/embeddings/Initializer/random_uniform/shape (Const) embedding/embeddings/Initializer/random_uniform/min (Const) embedding/embeddings/Initializer/random_uniform/max (Const) embedding/embeddings/Initializer/random_uniform/RandomUniform (RandomUniform) framework assigned device=/job:localhost/replica:0/task:0/device:GPU:0 embedding/embeddings/Initializer/random_uniform/sub (Sub) embedding/embeddings/Initializer/random_uniform/mul (Mul) embedding/embeddings/Initializer/random_uniform (Add) embedding/embeddings (VarHandleOp) framework assigned device=/job:localhost/replica:0/task:0/device:GPU:0 embedding/embeddings/IsInitialized/VarIsInitializedOp (VarIsInitializedOp) framework assigned device=/job:localhost/replica:0/task:0/device:GPU:0 embedding/embeddings/Assign (AssignVariableOp) framework assigned device=/job:localhost/replica:0/task:0/device:GPU:0 embedding/embeddings/Read/ReadVariableOp (ReadVariableOp) framework assigned device=/job:localhost/replica:0/task:0/device:GPU:0 embedding/embedding_lookup (ResourceGather) framework assigned device=/job:localhost/replica:0/task:0/device:GPU:0 embedding/embedding_lookup/Identity (Identity) AssignVariableOp (AssignVariableOp) framework assigned device=/job:localhost/replica:0/task:0/device:GPU:0 ReadVariableOp (ReadVariableOp) framework assigned device=/job:localhost/replica:0/task:0/device:GPU:0 VarIsInitializedOp_5 (VarIsInitializedOp) framework assigned device=/job:localhost/replica:0/task:0/device:GPU:0 SGD/embedding/embeddings/momentum/Initializer/zeros/shape_as_tensor (Const) SGD/embedding/embeddings/momentum/Initializer/zeros/Const (Const) SGD/embedding/embeddings/momentum/Initializer/zeros (Fill) SGD/embedding/embeddings/momentum (VarHandleOp) SGD/embedding/embeddings/momentum/IsInitialized/VarIsInitializedOp (VarIsInitializedOp) SGD/embedding/embeddings/momentum/Assign (AssignVariableOp) SGD/embedding/embeddings/momentum/Read/ReadVariableOp (ReadVariableOp) SGD/SGD/update_embedding/embeddings/ResourceSparseApplyKerasMomentum (ResourceSparseApplyKerasMomentum) VarIsInitializedOp_15 (VarIsInitializedOp)

 [[{{node embedding/embeddings/Initializer/random_uniform/sub}}]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "//MyProject/Chinese-Word-Segmentation/code/predict.py", line 40, in predict(input_path, output_path, resources_path) File "//MyProject/Chinese-Word-Segmentation/code/predict.py", line 31, in predict predict_model(input_path, output_path, resources_path) File "//MyProject/Chinese-Word-Segmentation/code/model.py", line 109, in predict_model model = load_model(model_path, custom_objects={"precision": precision}) File "//anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/keras/saving/save.py", line 146, in load_model return hdf5_format.load_model_from_hdf5(filepath, custom_objects, compile) File "//anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/keras/saving/hdf5_format.py", line 256, in load_model_from_hdf5 model.optimizer.set_weights(optimizer_weight_values) File "//anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/keras/optimizer_v2/optimizer_v2.py", line 724, in set_weights param_values = backend.batch_get_value(params) File "//anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/keras/backend.py", line 3010, in batch_get_value return get_session(tensors).run(tensors) File "//anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/keras/backend.py", line 462, in get_session _initialize_variables(session) File "//anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/keras/backend.py", line 879, in _initialize_variables [variables_module.is_variable_initialized(v) for v in candidate_vars]) File "//anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 950, in run run_metadata_ptr) File "//anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1173, in _run feed_dict_tensor, options, run_metadata) File "//anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1350, in _do_run run_metadata) File "//anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1370, in _do_call raise type(e)(node_def, op, message) tensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot assign a device for operation embedding/embeddings/Initializer/random_uniform/sub: Could not satisfy explicit device specification '' because the node node embedding/embeddings/Initializer/random_uniform/sub (defined at /MyProject/Chinese-Word-Segmentation/code/model.py:109) placed on device Device assignments active during op 'embedding/embeddings/Initializer/random_uniform/sub' creation: with tf.device(None): <//anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/ops/resource_variable_ops.py:602> was colocated with a group of nodes that required incompatible device '/job:localhost/replica:0/task:0/device:GPU:0'. All available devices [/job:localhost/replica:0/task:0/device:CPU:0, /job:localhost/replica:0/task:0/device:XLA_CPU:0, /job:localhost/replica:0/task:0/device:GPU:0, /job:localhost/replica:0/task:0/device:XLA_GPU:0]. Colocation Debug Info: Colocation group had the following types and supported devices: Root Member(assigned_device_nameindex=1 requested_devicename='/job:localhost/replica:0/task:0/device:GPU:0' assigned_devicename='/job:localhost/replica:0/task:0/device:GPU:0' resource_devicename='/job:localhost/replica:0/task:0/device:GPU:0' supported_devicetypes=[CPU] possibledevices=[] ResourceSparseApplyKerasMomentum: CPU Sub: GPU CPU XLA_CPU XLA_GPU Add: GPU CPU XLA_CPU XLA_GPU Fill: GPU CPU XLA_CPU XLA_GPU Mul: GPU CPU XLA_CPU XLA_GPU Const: GPU CPU XLA_CPU XLA_GPU RandomUniform: GPU CPU XLA_CPU XLA_GPU ReadVariableOp: GPU CPU XLA_CPU XLA_GPU VarIsInitializedOp: GPU CPU XLA_CPU XLA_GPU VarHandleOp: GPU CPU XLA_CPU XLA_GPU AssignVariableOp: GPU CPU XLA_CPU XLA_GPU ResourceGather: GPU CPU XLA_CPU XLA_GPU Identity: GPU CPU XLA_CPU XLA_GPU

Colocation members, user-requested devices, and framework assigned devices, if any: embedding/embeddings/Initializer/random_uniform/shape (Const) embedding/embeddings/Initializer/random_uniform/min (Const) embedding/embeddings/Initializer/random_uniform/max (Const) embedding/embeddings/Initializer/random_uniform/RandomUniform (RandomUniform) framework assigned device=/job:localhost/replica:0/task:0/device:GPU:0 embedding/embeddings/Initializer/random_uniform/sub (Sub) embedding/embeddings/Initializer/random_uniform/mul (Mul) embedding/embeddings/Initializer/random_uniform (Add) embedding/embeddings (VarHandleOp) framework assigned device=/job:localhost/replica:0/task:0/device:GPU:0 embedding/embeddings/IsInitialized/VarIsInitializedOp (VarIsInitializedOp) framework assigned device=/job:localhost/replica:0/task:0/device:GPU:0 embedding/embeddings/Assign (AssignVariableOp) framework assigned device=/job:localhost/replica:0/task:0/device:GPU:0 embedding/embeddings/Read/ReadVariableOp (ReadVariableOp) framework assigned device=/job:localhost/replica:0/task:0/device:GPU:0 embedding/embedding_lookup (ResourceGather) framework assigned device=/job:localhost/replica:0/task:0/device:GPU:0 embedding/embedding_lookup/Identity (Identity) AssignVariableOp (AssignVariableOp) framework assigned device=/job:localhost/replica:0/task:0/device:GPU:0 ReadVariableOp (ReadVariableOp) framework assigned device=/job:localhost/replica:0/task:0/device:GPU:0 VarIsInitializedOp_5 (VarIsInitializedOp) framework assigned device=/job:localhost/replica:0/task:0/device:GPU:0 SGD/embedding/embeddings/momentum/Initializer/zeros/shape_as_tensor (Const) SGD/embedding/embeddings/momentum/Initializer/zeros/Const (Const) SGD/embedding/embeddings/momentum/Initializer/zeros (Fill) SGD/embedding/embeddings/momentum (VarHandleOp) SGD/embedding/embeddings/momentum/IsInitialized/VarIsInitializedOp (VarIsInitializedOp) SGD/embedding/embeddings/momentum/Assign (AssignVariableOp) SGD/embedding/embeddings/momentum/Read/ReadVariableOp (ReadVariableOp) SGD/SGD/update_embedding/embeddings/ResourceSparseApplyKerasMomentum (ResourceSparseApplyKerasMomentum) VarIsInitializedOp_15 (VarIsInitializedOp)

 [[node embedding/embeddings/Initializer/random_uniform/sub (defined at /MyProject/Chinese-Word-Segmentation/code/model.py:109) ]]Additional information about colocations:No node-device colocations were active during op 'embedding/embeddings/Initializer/random_uniform/sub' creation.

Device assignments active during op 'embedding/embeddings/Initializer/random_uniform/sub' creation: with tf.device(None): </anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/ops/resource_variable_ops.py:602>

Original stack trace for 'embedding/embeddings/Initializer/random_uniform/sub': File "/MyProject/Chinese-Word-Segmentation/code/predict.py", line 40, in predict(input_path, output_path, resources_path) File "/MyProject/Chinese-Word-Segmentation/code/predict.py", line 31, in predict predict_model(input_path, output_path, resources_path) File "/MyProject/Chinese-Word-Segmentation/code/model.py", line 109, in predict_model model = load_model(model_path, custom_objects={"precision": precision}) File "/anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/keras/saving/save.py", line 146, in load_model return hdf5_format.load_model_from_hdf5(filepath, custom_objects, compile) File "/anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/keras/saving/hdf5_format.py", line 212, in load_model_from_hdf5 custom_objects=custom_objects) File "/anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/keras/saving/model_config.py", line 55, in model_from_config return deserialize(config, custom_objects=custom_objects) File "/anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/keras/layers/serialization.py", line 89, in deserialize printable_module_name='layer') File "/anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/keras/utils/generic_utils.py", line 192, in deserialize_keras_object list(custom_objects.items()))) File "/anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/keras/engine/network.py", line 1131, in from_config process_node(layer, node_data) File "/anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/keras/engine/network.py", line 1087, in process_node layer(flat_input_tensors[0], kwargs) File "/anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py", line 591, in call self._maybe_build(inputs) File "/anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py", line 1881, in _maybe_build self.build(input_shapes) File "/anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/keras/utils/tf_utils.py", line 295, in wrapper output_shape = fn(instance, input_shape) File "/anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/keras/layers/embeddings.py", line 141, in build constraint=self.embeddings_constraint) File "/anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer.py", line 384, in add_weight aggregation=aggregation) File "/anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/training/tracking/base.py", line 663, in _add_variable_with_custom_getter kwargs_for_getter) File "/anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer_utils.py", line 155, in make_variable shape=variable_shape if variable_shape.rank else None) File "/anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/ops/variables.py", line 259, in call return cls._variable_v1_call(*args, kwargs) File "/anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/ops/variables.py", line 220, in _variable_v1_call shape=shape) File "/anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/ops/variables.py", line 198, in previous_getter = lambda kwargs: default_variable_creator(None, *kwargs) File "/anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/ops/variable_scope.py", line 2495, in default_variable_creator shape=shape) File "/anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/ops/variables.py", line 263, in call return super(VariableMetaclass, cls).call(args, kwargs) File "/anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/ops/resource_variable_ops.py", line 460, in init shape=shape) File "/anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/ops/resource_variable_ops.py", line 604, in _init_from_args initial_value() if init_from_fn else initial_value, File "/anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/keras/engine/base_layer_utils.py", line 135, in init_val = lambda: initializer(shape, dtype=dtype) File "/anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/ops/init_ops.py", line 283, in call shape, self.minval, self.maxval, dtype, seed=self.seed) File "/anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/ops/random_ops.py", line 248, in random_uniform return math_ops.add(rnd (maxval - minval), minval, name=name) File "/anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/ops/math_ops.py", line 884, in binary_op_wrapper return func(x, y, name=name) File "/anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/ops/gen_math_ops.py", line 10855, in sub "Sub", x=x, y=y, name=name) File "/anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 788, in _apply_op_helper op_def=op_def) File "/anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 507, in new_func return func(args, kwargs) File "/anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3616, in create_op op_def=op_def) File "/anaconda3/envs/tf14/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 2005, in init self._traceback = tf_stack.extract_stack()

Process finished with exit code 1

I got this result, i dont know why。can you help me ,thank you !!!

rxc205 commented 4 years ago

a

i train the model for 100 epochs the best weights only saved the 4th epoch's. But the accuracy is still increasing .