google-research / exoplanet-ml

Machine learning models and utilities for exoplanet science.
Apache License 2.0
294 stars 117 forks source link

ValueError: could not broadcast input array from shape (4,43) into shape (4,39) #14

Open stefanofisc opened 4 years ago

stefanofisc commented 4 years ago

Hi, I'm trying to create training, validation and test files in "Process Kepler Data" section. Unit test pass, bazel build done without any problems and all tensorflow libraries are correct.

# Preprocess light curves into sharded TFRecord files using 5 worker processes.
bazel-bin/astronet/data/generate_input_records \
  --input_tce_csv_file=${TCE_CSV_FILE} \
  --kepler_data_dir=${KEPLER_DATA_DIR} \
  --output_dir=${TFRECORD_DIR} \
  --num_worker_processes=5

The process seems to start without any issues and it starts to create files, but after a while i get this error:

Traceback (most recent call last):

File "/home/s.fiscale/anaconda3/envs/astronet_env/lib/python3.7/multiprocessing/pool.py", line 121, in worker result = (True, func(*args, **kwds)) File "/home/s.fiscale/conda/exoplanet-ml/exoplanet-ml/bazel-bin/astronet/data/generate_input_records.runfiles/main/astronet/data/generate_input_records.py", line 164, in _process_file_shard example = _process_tce(tce) File "/home/s.fiscale/conda/exoplanet-ml/exoplanet-ml/bazel-bin/astronet/data/generate_input_records.runfiles/main/astronet/data/generate_input_records.py", line 144, in _process_tce time, flux = preprocess.process_light_curve(all_time, all_flux) File "/home/s.fiscale/conda/exoplanet-ml/exoplanet-ml/bazel-bin/astronet/data/generate_input_records.runfiles/main/astronet/data/preprocess.py", line 72, in process_light_curve spline = kepler_spline.fit_kepler_spline(all_time, all_flux, verbose=False)[0] File "/home/s.fiscale/conda/exoplanet-ml/exoplanet-ml/bazel-bin/astronet/data/generate_input_records.runfiles/main/third_party/kepler_spline/kepler_spline.py", line 321, in fit_kepler_spline verbose=verbose) File "/home/s.fiscale/conda/exoplanet-ml/exoplanet-ml/bazel-bin/astronet/data/generate_input_records.runfiles/main/third_party/kepler_spline/kepler_spline.py", line 216, in choose_kepler_spline time, flux, bkspace=bkspace, maxiter=maxiter) File "/home/s.fiscale/conda/exoplanet-ml/exoplanet-ml/bazel-bin/astronet/data/generate_input_records.runfiles/main/third_party/kepler_spline/kepler_spline.py", line 104, in kepler_spline curve = bspline.iterfit(time[mask], flux[mask], bkspace=bkspace)[0] File "/home/s.fiscale/anaconda3/envs/astronet_env/lib/python3.7/site-packages/pydl/pydlutils/bspline.py", line 639, in iterfit x2=x2work) File "/home/s.fiscale/anaconda3/envs/astronet_env/lib/python3.7/site-packages/pydl/pydlutils/bspline.py", line 189, in fit errb = cholesky_band(alpha, mininf=min_influence) File "/home/s.fiscale/anaconda3/envs/astronet_env/lib/python3.7/site-packages/pydl/pydlutils/bspline.py", line 491, in cholesky_band L[:, 0:n] = lower ValueError: could not broadcast input array from shape (4,43) into shape (4,39) """

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/home/s.fiscale/conda/exoplanet-ml/exoplanet-ml/bazel-bin/astronet/data/generate_input_records.runfiles/main/astronet/data/generate_input_records.py", line 256, in tf.app.run(main=main, argv=[sys.argv[0]] + unparsed) File "/home/s.fiscale/anaconda3/envs/astronet_env/lib/python3.7/site-packages/tensorflow_core/python/platform/app.py", line 40, in run _run(main=main, argv=argv, flags_parser=_parse_flags_tolerate_undef) File "/home/s.fiscale/anaconda3/envs/astronet_env/lib/python3.7/site-packages/absl/app.py", line 299, in run _run_main(main, args) File "/home/s.fiscale/anaconda3/envs/astronet_env/lib/python3.7/site-packages/absl/app.py", line 250, in _run_main sys.exit(main(argv)) File "/home/s.fiscale/conda/exoplanet-ml/exoplanet-ml/bazel-bin/astronet/data/generate_input_records.runfiles/main/astronet/data/generate_input_records.py", line 248, in main async_result.get() File "/home/s.fiscale/anaconda3/envs/astronet_env/lib/python3.7/multiprocessing/pool.py", line 657, in get raise self._value

ValueError: could not broadcast input array from shape (4,43) into shape (4,39)

I have no idea about how to fix this error. Can someone help me here?

Singh2202 commented 4 years ago

Hey mate! Did you by any chance get this issue resolved?

eakilli commented 3 years ago

Hi, after spending some time on this issue I figured out that this happens due to iterations of spline fit (set to 5 number of iterations by default). Since at each iteration the algorithm removes some outlier data points, it sometimes happens that it removes too many points and starts to violate some conditions of the spline fit. So by restricting the number of iterations or exiting the iteration procedure if there is a violation helps getting rid of the error. This should not affect the performance so much because after the first fit we already have a relatively good spline and the iterations are there simply to try and see if we can improve it. I hope this will help the others facing the same issue and will be happy to hear if anyone has feedback!

Txway commented 2 years ago

Hi, after spending some time on this issue I figured out that this happens due to iterations of spline fit (set to 5 number of iterations by default). Since at each iteration the algorithm removes some outlier data points, it sometimes happens that it removes too many points and starts to violate some conditions of the spline fit. So by restricting the number of iterations or exiting the iteration procedure if there is a violation helps getting rid of the error. This should not affect the performance so much because after the first fit we already have a relatively good spline and the iterations are there simply to try and see if we can improve it. I hope this will help the others facing the same issue and will be happy to hear if anyone has feedback!

Can you tell me what's exactly i have to do with this? I mean, what iterations? Which parts of code that i have to change?

RichardScottOZ commented 2 years ago

Here https://github.com/google-research/exoplanet-ml/blob/master/exoplanet-ml/third_party/kepler_spline/kepler_spline.py

I presume the iterations passed in the above - set that to 1 or make a handler as suggested above.

Txway commented 2 years ago

Hello Sir, looks like you know a lot about this exoplanet-ml project. So I came across another error when I tried to train the linear model (Astro Model). The error said:

ValueError: Can not squeeze dim[1], expected a dimension of 1, got 2001 for 'Squeeze' (op: 'Squeeze') with input shapes: [?,2001,1]

It's like something wrong with the dimension. Do you know how to fix it? Sorry again for bothering you.

On Tue, 25 Jan 2022, 05:00 RichardScottOZ, @.***> wrote:

Here https://github.com/google-research/exoplanet-ml/blob/master/exoplanet-ml/third_party/kepler_spline/kepler_spline.py

I presume the iterations passed in the above - set that to 1 or make a handler as suggested above.

— Reply to this email directly, view it on GitHub https://github.com/google-research/exoplanet-ml/issues/14#issuecomment-1020589848, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXOGAJS7LZ7RA4DYYYMJJGDUXXDWHANCNFSM4OD7I5FQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you commented.Message ID: @.***>

RichardScottOZ commented 2 years ago

Is it around the wrong way?

Txway commented 2 years ago

I think so

On Thu, 11 Aug 2022, 19:24 RichardScottOZ, @.***> wrote:

Is it around the wrong way?

— Reply to this email directly, view it on GitHub https://github.com/google-research/exoplanet-ml/issues/14#issuecomment-1211918498, or unsubscribe https://github.com/notifications/unsubscribe-auth/AXOGAJS5QOCMQ7U4AMD22RLVYTWHZANCNFSM4OD7I5FQ . You are receiving this because you commented.Message ID: @.***>