Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.10"]
python-version: ["3.10", "3.11"]

steps:
- name: Checkout repository
Expand Down
41 changes: 40 additions & 1 deletion FLiESANN/run_FLiES_ANN_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,47 @@ def run_FLiES_ANN_inference(
split_atypes_ctypes=split_atypes_ctypes
)

# Convert DataFrame to numpy array and reshape for the model
inputs_array = inputs.values

# Check what input shape the model expects and adapt accordingly
# Different TensorFlow/Keras versions may have different input requirements
try:
model_input_shape = ANN_model.input_shape
if len(model_input_shape) == 3:
# Model expects 3D input: (batch_size, sequence_length, features)
# Reshape from (batch_size, features) to (batch_size, 1, features)
inputs_array = inputs_array.reshape(inputs_array.shape[0], 1, inputs_array.shape[1])
expects_3d = True
elif len(model_input_shape) == 2:
# Model expects 2D input: (batch_size, features)
# Keep the original 2D shape
expects_3d = False
else:
# Fallback: try 2D first
expects_3d = False
except (AttributeError, TypeError):
# If input_shape is not available, try 2D first
expects_3d = False

# Run inference using the ANN model
outputs = ANN_model.predict(inputs)
try:
outputs = ANN_model.predict(inputs_array)
except ValueError as e:
error_msg = str(e)
if not expects_3d and ("expected shape" in error_msg or "incompatible" in error_msg):
# Try reshaping to 3D if 2D failed
inputs_array = inputs.values # Reset to original 2D shape
inputs_array = inputs_array.reshape(inputs_array.shape[0], 1, inputs_array.shape[1])
outputs = ANN_model.predict(inputs_array)
expects_3d = True
else:
raise e

# Handle output dimensions based on input dimensions used
if expects_3d and len(outputs.shape) == 3:
outputs = outputs.squeeze(axis=1)

shape = COT.shape

# Prepare the results dictionary
Expand Down
2 changes: 1 addition & 1 deletion FLiESANN/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.4.2
1.5.0
9,129 changes: 21 additions & 9,108 deletions Processing FLiES with a raster and default parameters.ipynb

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ requires = ["setuptools>=60", "setuptools-scm>=8.0", "wheel"]

[project]
name = "FLiESANN"
version = "1.4.2"
version = "1.5.0"
description = "Forest Light Environmental Simulator (FLiES) Radiative Transfer Model Artificial Neural Network (ANN) Implementation in Python"
readme = "README.md"
authors = [
Expand All @@ -15,7 +15,7 @@ classifiers = [
]
dependencies = [
"GEOS5FP>=1.1.1",
"keras==2.15",
"keras",
"koppengeiger",
"MCD12C1-2019-v006",
"NASADEM>=1.1.1",
Expand All @@ -26,7 +26,7 @@ dependencies = [
"sentinel-tiles",
"solar-apparent-time",
"sun-angles",
"tensorflow==2.15.1"
"tensorflow"
]

requires-python = ">=3.10"
Expand Down