p2irc / deepplantphenomics

Deep learning for plant phenotyping.
GNU General Public License v2.0
133 stars 46 forks source link

Bug fixes for Issue #25 and Setting Loss Functions #28

Closed donovanlavoie closed 5 years ago

donovanlavoie commented 5 years ago

This should fix Issue #25. Setting the loss function when the problem type was set to regression was problematic since a typo was comparing the desired regression loss function to the loss function for classification.

I also determined that set_loss_function would never succeed under normal circumstances anyway since, even with correct inputs, it would just throw a warning and exit the program. An example is mentioned in a comment on Issue #25 and is repeated here for convenience:

>>> import deepplantphenomics as dpp
# numpy whining...
>>> model = dpp.DPPModel(debug=True, save_checkpoints=False)
11:29AM: TensorFlow loaded...
WARNING: Logging before flag parsing goes to stderr.
W0806 11:29:38.519376 139999384954688 deprecation_wrapper.py:119] From /home/donovan/deepplantphenomics/deepplantphenomics/deepplantpheno.py:211: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.

2019-08-06 11:29:38.543240: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 3392290000 Hz
2019-08-06 11:29:38.544092: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x42e1f00 executing computations on platform Host. Devices:
2019-08-06 11:29:38.544127: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): <undefined>, <undefined>
>>> model.set_problem_type('regression')
>>> model.set_loss_function('l2')
/home/donovan/deepplantphenomics/deepplantphenomics/deepplantpheno.py:448: UserWarning: Loss function and/or problem type not recognized. See documentation for list of supported functions and problem types.
  "functions and problem types.")

Process finished with exit code 0

set_loss_function was re-written to perform its checks for valid problem type and loss function properly and succeed with correct inputs. Regression tests were added for these cases as well. The above example with the changes is as follows:

>>> import deepplantphenomics as dpp
# numpy whining...
>>> model = dpp.DPPModel(debug=True, save_checkpoints=False)
02:46PM: TensorFlow loaded...
WARNING: Logging before flag parsing goes to stderr.
W0806 14:46:57.951786 140467759302464 deprecation_wrapper.py:119] From /home/donovan/deepplantphenomics/deepplantphenomics/deepplantpheno.py:206: The name tf.Session is deprecated. Please use tf.compat.v1.Session instead.

2019-08-06 14:46:57.975324: I tensorflow/core/platform/profile_utils/cpu_utils.cc:94] CPU Frequency: 3392290000 Hz
2019-08-06 14:46:57.975936: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x4987750 executing computations on platform Host. Devices:
2019-08-06 14:46:57.975964: I tensorflow/compiler/xla/service/service.cc:175]   StreamExecutor device (0): <undefined>, <undefined>
>>> model.set_problem_type('regression')
>>> model.set_loss_function('l2')
>>>