Skip to content

Commit c4b9037

Browse files
Merge pull request #22 from gregory-halverson/main
upgrading to python 3.11 and tensorflow 2.19
2 parents 99b6e54 + 774b282 commit c4b9037

File tree

5 files changed

+66
-9114
lines changed

5 files changed

+66
-9114
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
runs-on: ubuntu-latest
1414
strategy:
1515
matrix:
16-
python-version: ["3.10"]
16+
python-version: ["3.10", "3.11"]
1717

1818
steps:
1919
- name: Checkout repository

FLiESANN/run_FLiES_ANN_inference.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,47 @@ def run_FLiES_ANN_inference(
7070
split_atypes_ctypes=split_atypes_ctypes
7171
)
7272

73+
# Convert DataFrame to numpy array and reshape for the model
74+
inputs_array = inputs.values
75+
76+
# Check what input shape the model expects and adapt accordingly
77+
# Different TensorFlow/Keras versions may have different input requirements
78+
try:
79+
model_input_shape = ANN_model.input_shape
80+
if len(model_input_shape) == 3:
81+
# Model expects 3D input: (batch_size, sequence_length, features)
82+
# Reshape from (batch_size, features) to (batch_size, 1, features)
83+
inputs_array = inputs_array.reshape(inputs_array.shape[0], 1, inputs_array.shape[1])
84+
expects_3d = True
85+
elif len(model_input_shape) == 2:
86+
# Model expects 2D input: (batch_size, features)
87+
# Keep the original 2D shape
88+
expects_3d = False
89+
else:
90+
# Fallback: try 2D first
91+
expects_3d = False
92+
except (AttributeError, TypeError):
93+
# If input_shape is not available, try 2D first
94+
expects_3d = False
95+
7396
# Run inference using the ANN model
74-
outputs = ANN_model.predict(inputs)
97+
try:
98+
outputs = ANN_model.predict(inputs_array)
99+
except ValueError as e:
100+
error_msg = str(e)
101+
if not expects_3d and ("expected shape" in error_msg or "incompatible" in error_msg):
102+
# Try reshaping to 3D if 2D failed
103+
inputs_array = inputs.values # Reset to original 2D shape
104+
inputs_array = inputs_array.reshape(inputs_array.shape[0], 1, inputs_array.shape[1])
105+
outputs = ANN_model.predict(inputs_array)
106+
expects_3d = True
107+
else:
108+
raise e
109+
110+
# Handle output dimensions based on input dimensions used
111+
if expects_3d and len(outputs.shape) == 3:
112+
outputs = outputs.squeeze(axis=1)
113+
75114
shape = COT.shape
76115

77116
# Prepare the results dictionary

FLiESANN/version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.4.2
1+
1.5.0

Processing FLiES with a raster and default parameters.ipynb

Lines changed: 21 additions & 9108 deletions
Large diffs are not rendered by default.

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ requires = ["setuptools>=60", "setuptools-scm>=8.0", "wheel"]
33

44
[project]
55
name = "FLiESANN"
6-
version = "1.4.2"
6+
version = "1.5.0"
77
description = "Forest Light Environmental Simulator (FLiES) Radiative Transfer Model Artificial Neural Network (ANN) Implementation in Python"
88
readme = "README.md"
99
authors = [
@@ -15,7 +15,7 @@ classifiers = [
1515
]
1616
dependencies = [
1717
"GEOS5FP>=1.1.1",
18-
"keras==2.15",
18+
"keras",
1919
"koppengeiger",
2020
"MCD12C1-2019-v006",
2121
"NASADEM>=1.1.1",
@@ -26,7 +26,7 @@ dependencies = [
2626
"sentinel-tiles",
2727
"solar-apparent-time",
2828
"sun-angles",
29-
"tensorflow==2.15.1"
29+
"tensorflow"
3030
]
3131

3232
requires-python = ">=3.10"

0 commit comments

Comments
 (0)