silx-kit / freesas

Small angle scattering tools ... but unlike most others, free.
MIT License
12 stars 11 forks source link

DenseNeuralNetwork #86

Closed Mayank2184 closed 4 months ago

Mayank2184 commented 4 months ago

to predict Rg and Dmax

kif commented 4 months ago

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 commented 4 months ago

Yes, I did it was working perfectly there.....

On Thu, 4 Jul, 2024, 18:17 Jerome Kieffer, @.***> wrote:

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[2i], 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

— Reply to this email directly, view it on GitHub https://github.com/silx-kit/freesas/pull/86#issuecomment-2209302115, or unsubscribe https://github.com/notifications/unsubscribe-auth/BHAURYIOYSXCKMISTHDAYJDZKVYQBAVCNFSM6AAAAABKB5SXSSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMBZGMYDEMJRGU . You are receiving this because you authored the thread.Message ID: @.***>

kif commented 4 months ago

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