Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DenseNeuralNetwork #86

Merged
merged 10 commits into from
Jul 5, 2024
Merged

DenseNeuralNetwork #86

merged 10 commits into from
Jul 5, 2024

Conversation

Mayank2184
Copy link
Contributor

to predict Rg and Dmax

src/freesas/dnn.py Show resolved Hide resolved
src/freesas/dnn.py Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The best would be to use this .keras file (can be updated later on when everything is converged) rather than the config.json, model.weights.h5 and metadata.json. Is it possible to make a function that reads a .keras file in dnn.py and return a DNN object.

@kif
Copy link
Member

kif commented Jul 4, 2024

Did you check your code ?


In [9]: import freesas.resources

In [10]: freesas.resources.resource_filename("keras_models/Rg+Dmax.keras")
Out[10]: '/home/kieffer/.venv/py311/lib/python3.11/site-packages/freesas/resources/keras_models/Rg+Dmax.keras'

In [11]: k=freesas.resources.resource_filename("keras_models/Rg+Dmax.keras")

In [12]: freesas.dnn.KerasDNN(k)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[12], line 1
----> 1 freesas.dnn.KerasDNN(k)

File ~/.venv/py311/lib/python3.11/site-packages/freesas/dnn.py:154, in KerasDNN.__init__(self, keras_file)
    153 def __init__(self, keras_file):
--> 154     config, weights = parse_keras_file(keras_file)
    155     self.dnn =  DNN(*[DenseLayer(weights[2*i], weights[2*i+1], a) for i,a in enumerate(config[1])])

File ~/.venv/py311/lib/python3.11/site-packages/freesas/dnn.py:146, in parse_keras_file(keras_file)
    144 with zipfile.ZipFile(keras_file, 'r') as z:
    145     with z.open('config.json') as config_file:
--> 146         config = parse_config(config_file)
    147     with z.open('model.weights.h5') as weights_file:
    148         weights = load_weights(weights_file, config[0])

File ~/.venv/py311/lib/python3.11/site-packages/freesas/dnn.py:31, in parse_config(config_path)
     30 def parse_config(config_path):
---> 31     with open(config_path, 'r') as f:
     32         config = json.load(f)
     34     layer_dims = []

TypeError: expected str, bytes or os.PathLike object, not ZipExtFile

@Mayank2184
Copy link
Contributor Author

Mayank2184 commented Jul 4, 2024 via email

@kif
Copy link
Member

kif commented Jul 5, 2024

It should almost be OK for the json part. I will have a look.

For the hdf5 side, I foresee some issues, one should probably go via io.BytesIO see:
https://docs.python.org/3/library/io.html

Copy link
Member

@kif kif left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kif kif merged commit b61ba75 into silx-kit:main Jul 5, 2024
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants