COVID19BIOSTAT / covid19_prediction

Survival-Convolution Model for COVID-19 Prediction
Apache License 2.0
16 stars 3 forks source link

Example in README doesn't work #2

Open vladimirvrabely opened 4 years ago

vladimirvrabely commented 4 years ago

Hi,

I have an issue when running when the example provided in README.md. This is my setup:

$ python --version
Python 3.6.12

and

$ pip freeze | grep 'scikit\|numpy\|tensorflow'
numpy==1.18.5
scikit-learn==0.23.2
tensorflow==2.0.3
tensorflow-estimator==2.0.1

When I run the model on train data

cd  covid19_prediction
python python/run_single_machine_model.py --knots=23,28 --input_path="example/train_data.npy" --output_path="example/output" --max_epochs=2000 --initial_a=0.5,0.5,0.5 --learning_rate=0.01

I get the following error about float32 and float64 mismatch:

2020-10-20 19:44:48.831023: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2020-10-20 19:44:48.852006: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 3699435000 Hz
2020-10-20 19:44:48.853291: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x563dd7bf64f0 executing computations on platform Host. Devices:
2020-10-20 19:44:48.853341: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): Host, Default Version
WARNING:tensorflow:Can save best model only with loss available, skipping.
W1020 19:44:49.719795 139666594617152 callbacks.py:990] Can save best model only with loss available, skipping.
Traceback (most recent call last):
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/framework/op_def_library.py", line 471, in _apply_op_helper
    as_ref=input_arg.is_ref)
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py", line 1365, in internal_convert_n_to_tensor
    ctx=ctx))
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/framework/ops.py", line 1271, in internal_convert_to_tensor
    (dtype.name, value.dtype.name, value))
ValueError: Tensor conversion requested dtype float32 for Tensor with dtype float64: <tf.Tensor 'gradients/Tensordot/transpose_grad/transpose:0' shape=<unknown> dtype=float64>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "python/run_single_machine_model.py", line 64, in <module>
    app.run(main)
  File "/home/.venv/lib/python3.6/site-packages/absl/app.py", line 300, in run
    _run_main(main, args)
  File "/home/.venv/lib/python3.6/site-packages/absl/app.py", line 251, in _run_main
    sys.exit(main(argv))
  File "python/run_single_machine_model.py", line 33, in main
    estimator.fit(data=input_data, min_t0=FLAGS.min_t0, max_t0=FLAGS.max_t0)
  File "/home/covid19_prediction/python/piecewise_linear_infection_model.py", line 364, in fit
    min_t0, max_t0 + 1)]
  File "/home/covid19_prediction/python/piecewise_linear_infection_model.py", line 363, in <listcomp>
    self._fit_with_t0(data, t0, message) for t0 in range(
  File "/home/covid19_prediction/python/piecewise_linear_infection_model.py", line 337, in _fit_with_t0
    batch_size=len(data) + t0, shuffle=False, verbose=0, callbacks=[mcp])
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/training.py", line 728, in fit
    use_multiprocessing=use_multiprocessing)
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/training_v2.py", line 324, in fit
    total_epochs=epochs)
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/training_v2.py", line 123, in run_one_epoch
    batch_outs = execution_function(iterator)
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/training_v2_utils.py", line 86, in execution_function
    distributed_function(input_fn))
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/eager/def_function.py", line 457, in __call__
    result = self._call(*args, **kwds)
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/eager/def_function.py", line 503, in _call
    self._initialize(args, kwds, add_initializers_to=initializer_map)
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/eager/def_function.py", line 408, in _initialize
    *args, **kwds))
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/eager/function.py", line 1848, in _get_concrete_function_internal_garbage_collected
    graph_function, _, _ = self._maybe_define_function(args, kwargs)
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/eager/function.py", line 2150, in _maybe_define_function
    graph_function = self._create_graph_function(args, kwargs)
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/eager/function.py", line 2041, in _create_graph_function
    capture_by_value=self._capture_by_value),
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/framework/func_graph.py", line 915, in func_graph_from_py_func
    func_outputs = python_func(*func_args, **func_kwargs)
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/eager/def_function.py", line 358, in wrapped_fn
    return weak_wrapped_fn().__wrapped__(*args, **kwds)
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/training_v2_utils.py", line 73, in distributed_function
    per_replica_function, args=(model, x, y, sample_weights))
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/distribute/distribute_lib.py", line 760, in experimental_run_v2
    return self._extended.call_for_each_replica(fn, args=args, kwargs=kwargs)
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/distribute/distribute_lib.py", line 1787, in call_for_each_replica
    return self._call_for_each_replica(fn, args, kwargs)
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/distribute/distribute_lib.py", line 2132, in _call_for_each_replica
    return fn(*args, **kwargs)
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/autograph/impl/api.py", line 292, in wrapper
    return func(*args, **kwargs)
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/training_v2_utils.py", line 264, in train_on_batch
    output_loss_metrics=model._output_loss_metrics)
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/training_eager.py", line 311, in train_on_batch
    output_loss_metrics=output_loss_metrics))
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/keras/engine/training_eager.py", line 268, in _process_single_batch
    grads = tape.gradient(scaled_total_loss, trainable_weights)
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/eager/backprop.py", line 1014, in gradient
    unconnected_gradients=unconnected_gradients)
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/eager/imperative_grad.py", line 76, in imperative_grad
    compat.as_str(unconnected_gradients.value))
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/eager/backprop.py", line 138, in _gradient_function
    return grad_fn(mock_op, *out_grads)
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/ops/while_v2.py", line 364, in _WhileGrad
    util.unique_grad_fn_name(body_graph.name), op, maximum_iterations)
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/ops/while_v2.py", line 607, in _create_grad_func
    body_graph_inputs, body_graph_outputs))
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/framework/func_graph.py", line 915, in func_graph_from_py_func
    func_outputs = python_func(*func_args, **func_kwargs)
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/ops/while_v2.py", line 603, in <lambda>
    lambda *args: _grad_fn(ys, xs, args, body_graph),
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/ops/while_v2.py", line 663, in _grad_fn
    unconnected_gradients="zero")
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/ops/gradients_util.py", line 607, in _GradientsHelper
    aggregation_method)
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/ops/gradients_util.py", line 1008, in _AggregatedGrads
    out_grads[i] = _MultiDeviceAddN(out_grad, gradient_uid)
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/ops/gradients_util.py", line 875, in _MultiDeviceAddN
    summands.append(math_ops.add_n(tensors))
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/util/dispatch.py", line 180, in wrapper
    return target(*args, **kwargs)
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/ops/math_ops.py", line 3018, in add_n
    return gen_math_ops.add_n(inputs, name=name)
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/ops/gen_math_ops.py", line 477, in add_n
    "AddN", inputs=inputs, name=name)
  File "/home/.venv/lib/python3.6/site-packages/tensorflow_core/python/framework/op_def_library.py", line 499, in _apply_op_helper
    raise TypeError("%s that don't all match." % prefix)
TypeError: Tensors in list passed to 'inputs' of 'AddN' Op have types [float32, float64] that don't all match.

What could be the problem?

Thanks in advance for any help you are able to provide.

Wenbofei commented 3 years ago

I met the same problem when using tensorflow 2.0, but problem solved when I upgraded tensorflow to 2.1.0, also python is under 3.7.