lluciesmith / DeepHalos

Deep learning dark matter halo formation
MIT License
5 stars 2 forks source link

No 'predictions_functions' file #1

Closed finn-dodgson closed 2 years ago

finn-dodgson commented 3 years ago

Hi,

I am trying to run the demo code and I run into this error: No module named 'predictions_functions'

I have looked through all folders in the repo, but I've been unable to find the file that defines the compare_two_violin_plots and violin_plot functions.

Thanks.

Screenshot 2021-10-25 142353

lluciesmith commented 3 years ago

Hi Finn,

Sorry about that. It must mean that those plotting routine are coming from one of my other repos. Sorry I will fix it as soon as possible!

Best, Luisa

finn-dodgson commented 3 years ago

Hi Luisa,

No worries. If you are able to add them to the repo, it would be greatly appreciated!

Kind regards, Finn

finn-dodgson commented 2 years ago

Hi Luisa,

Just wanted to follow-up on this: were you able to find the missing plotting routines?

Best, Finn

lluciesmith commented 2 years ago

Hi Finn,

Apologies for the delay! I have now added all the relevant files so you should not have importing issue anymore. Could you please git pull, try again and let me know if things work smoothly now? Thanks!

Best, Luisa

finn-dodgson commented 2 years ago

Hi Luisa,

No worries. It seems to be working now, thanks! I did have to change line 5 of utilss/radius_functions_deep.py to: from utilss import distinct_colours , line 10 of dlhalos_code/CNN.py to: from tensorflow.python.keras.utils.multi_gpu_utils import multi_gpu_model , and remove the alpha argument from line 43 of plots/plots_for_predictions.py. Finally, I wasn't able to get the very last cell of the demo notebook to run (even after setting local_machine = True in dlhalos_code/loss_functions.py), but that's not a problem.

Thanks, Finn

lluciesmith commented 2 years ago

Hi Finn,

Could you send a quick pull request with the modifications you mention to utilss/radius_functions_deep.py and dlhalos_code/CNN.py? Otherwise I can do it and you can git pull again.

Why are you not able to import loss_functions.py? Could you post the error message? If you have tensorflow installed you should be able to import the module just fine. The local_machine = True option should only be relevant if you don't have tensorflow installed on your local machine.

Best, Luisa

finn-dodgson commented 2 years ago

Hi Luisa,

I forked the repo and submitted the pull request. I think it worked, but I apologize in advance if I haven't done it correctly-- I am quite new to GitHub.

I am confused why I am getting this error on the last cell. It seems to happen whether local_machine is True or False. I double-checked and I have tensorflow installed.

Thanks for your help, Finn

Screenshot 2021-11-26 215654

lluciesmith commented 2 years ago

Thanks for the pull request! I merged it to the main branch.

Could you git pull and see if the likelihood distribution plotting routine now works? It should be fixed now. Sorry for the many issues.

Best, Luisa

finn-dodgson commented 2 years ago

Hi Luisa,

No problem. Unfortunately, the likelihood distribution plotting is still not working. It is failing with this error:


InvalidArgumentError Traceback (most recent call last)

in 10 gamma = Model.model.layers[-1].get_weights()[0][0] 11 f, a = pp.plot_likelihood_distribution(h_m_pred, true, gamma, scaler, bins=np.linspace(-1,1,50), fig=None, axes=None, ---> 12 title=None, legend=True, slices=slices) ~/DeepHalos/plots/plots_for_predictions.py in plot_likelihood_distribution(p, t, gamma, scaler, bins, fig, axes, color, title, legend, slices) 190 191 y_pred = np.repeat(mean_x, len(bins)) --> 192 liklih = np.exp(- L.loss(bins.reshape(-1, 1), y_pred.reshape(-1, 1))) 193 ___ = ax.plot(bins, liklih, color="k") 194 ~/DeepHalos/dlhalos_code/loss_functions.py in loss(self, y_true, y_pred) 109 110 def loss(self, y_true, y_pred): --> 111 return self._loss(y_true, y_pred) 112 113 def _loss(self, y_true, y_pred): ~/DeepHalos/dlhalos_code/loss_functions.py in _loss(self, y_true, y_pred) 115 116 mask_range = K.less_equal(K.abs(y_pred), K.ones_like(y_pred)) --> 117 range_term = tf.where(mask_range, self.loss_range(y_true, y_pred), zeros) 118 119 mask_neg = K.less(y_pred, -1 * K.ones_like(y_pred)) ~/DeepHalos/dlhalos_code/loss_functions.py in loss_range(self, y_true, y_pred) 164 165 def loss_range(self, y_true, y_pred): --> 166 return self.function_inside_boundary(y_true, y_pred, self.g, self.y_maximum, self.y_minimum) 167 168 def deriv_loss_range(self, y_true, y_pred): ~/DeepHalos/dlhalos_code/loss_functions.py in function_inside_boundary(self, y_true, y_pred, gamma, y_max, y_min) 182 def function_inside_boundary(self, y_true, y_pred, gamma, y_max, y_min): 183 r = (y_true - y_pred) / gamma --> 184 f = K.log(gamma) + K.log(1 + K.square(r)) + \ 185 K.log(tf.atan((y_max - y_pred) / gamma) - tf.atan((y_min - y_pred) / gamma)) 186 return f ~/anaconda3/lib/python3.7/site-packages/tensorflow/python/ops/math_ops.py in binary_op_wrapper(x, y) 1365 # r_binary_op_wrapper use different force_same_dtype values. 1366 x, y = maybe_promote_tensors(x, y, force_same_dtype=False) -> 1367 return func(x, y, name=name) 1368 except (TypeError, ValueError) as e: 1369 # Even if dispatching the op failed, the RHS may be a tensor aware ~/anaconda3/lib/python3.7/site-packages/tensorflow/python/util/dispatch.py in wrapper(*args, **kwargs) 204 """Call target, and fall back on dispatchers if there is a TypeError.""" 205 try: --> 206 return target(*args, **kwargs) 207 except (TypeError, ValueError): 208 # Note: convert_to_eager_tensor currently raises a ValueError, not a ~/anaconda3/lib/python3.7/site-packages/tensorflow/python/ops/math_ops.py in _add_dispatch(x, y, name) 1698 return gen_math_ops.add(x, y, name=name) 1699 else: -> 1700 return gen_math_ops.add_v2(x, y, name=name) 1701 1702 ~/anaconda3/lib/python3.7/site-packages/tensorflow/python/ops/gen_math_ops.py in add_v2(x, y, name) 453 return _result 454 except _core._NotOkStatusException as e: --> 455 _ops.raise_from_not_ok_status(e, name) 456 except _core._FallbackException: 457 pass ~/anaconda3/lib/python3.7/site-packages/tensorflow/python/framework/ops.py in raise_from_not_ok_status(e, name) 6939 message = e.message + (" name: " + name if name is not None else "") 6940 # pylint: disable=protected-access -> 6941 six.raise_from(core._status_to_exception(e.code, message), None) 6942 # pylint: enable=protected-access 6943 ~/anaconda3/lib/python3.7/site-packages/six.py in raise_from(value, from_value) InvalidArgumentError: cannot compute AddV2 as input #1(zero-based) was expected to be a float tensor but is a double tensor [Op:AddV2] Seems like it could be a simple fix if something just needs to be converted to float(). Best, Finn