-
Notifications
You must be signed in to change notification settings - Fork 268
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
Modification to run with multi-output models #154
Comments
I have updated to the latest development version of Talos and this issue still persists. The output to my model is as follows:
From the error message is appears that Talos looks for a max value of the y data. Given that this is a list of 3 numpy arrays it doesn't have a max and errors. Can Talos be updated to handle multi-input / multi-output models? Or is my understanding oh how to set this up incorrect? I am calling Talos like this (also my model runs fine when not using Talos): |
can you share the CNN_model you are using as input for Scan() |
Yes it is as follows: `def CNN_model(X_train, y_train, X_val, y_val, params):
|
Any news on the support of multiple outputs? |
@rarazac the good news is that this probably is the most likely next new feature candidate. I've changed the status label to correspond with the will. |
To add small background, in my own research as well as that of our wider research group, implementing ethnical considerations is a key interest, and multi output models seem to be a good place to start. |
@mikkokotila Thank you very much for your response! If the multiple output model uses the same labels, the following minimal example seems to work... import talos as tl
import tensorflow as tf
def getModelForSweep(x_train, y_train, x_val, y_val, params):
input_shape = (28, 28) # 28x28 pixels
inp = tf.keras.layers.Input(shape=input_shape, name="main_input")
# shared network
shared_net = tf.keras.layers.Dense(params['shared_fc'], activation="relu")(inp)
shared_network_out = tf.keras.layers.Flatten(name="shared_out")(shared_net)
# out_1
out_1 = tf.keras.layers.Dense(params['fc'])(shared_network_out)
out_1 = tf.keras.layers.Dense(10, activation="softmax", name="out_1")(out_1)
# out_2
out_2 = tf.keras.layers.Dense(params['fc'])(shared_network_out)
out_2 = tf.keras.layers.Dense(10, activation="softmax", name="out_2")(out_2)
# build compile and train the model
model = tf.keras.models.Model(inputs=inp, outputs=[out_1, out_2])
model.compile(optimizer=params['optimizer'],
metrics=['accuracy'],
loss={'out_1': tf.keras.losses.categorical_crossentropy,
'out_2':tf.keras.losses.categorical_crossentropy})
out = model.fit(x_train, [y_train, y_train], validation_split=0.1)
return out, model
# parameters for sweep
p = {
'lr': [0.01, 0.001, 0.0001],
'shared_fc': [32, 64],
'fc': [64, 128],
'optimizer': ['Adam', 'sgd'],
}
# load data
(mnist_train, train_labels), (mnist_test, test_labels) = tf.keras.datasets.mnist.load_data()
train_labels_hot = tf.keras.utils.to_categorical(train_labels, num_classes=10)
# sweep
tl.Scan(x=mnist_train, y=train_labels_hot,
params=p,
model=getModelForSweep,
grid_downsample=0.1,
experiment_no='1',
dataset_name='mnist') |
Thanks. Given that this runs ok, do I gather it right that the issue is simply down to being able to pass two separate |
This is now implemented in daily-dev:
Below is a working example for reference:
Thanks a lot for @rarazac for inputs and example model. |
ONE IMPORTANT POINT TO KEEP IN MIND You must explicitly pass validation data (as opposed to using the split argument). This is consistent with multi-input models, where also Talos expects passing validation data explicitly. |
IF I have a list as:
and test
is below is correct way to model.fit ?
When I run loss is nan |
@sarmadm No, the above is not correct. Please see the provided example carefully and make effort to follow it. Also you can just copy paste the example and run on your machine, and then work from there to implement your own data and configuration in it. |
I changed it to :
It runs but when going from one epoch to another in params this error shows :
|
@sarmadm as I had said, what you have to do is run the example provided on your system, and then work from there. If you would like to have user support for specific case of yours, then you could try and open a new issue for that. But first, you really have to look at the example carefully. Pay attention especially to this:
The case you are highlighting is clearly far from it, and will definitely cause errors. Closing this here as the actual matter is resolved, and the feature implemented and tested. |
It would be great if possible to allow the option of using multi-output Keras models.
It is currently stated in Scan.py that y should have shape (m, c) where c is the number of classes. This restricts to one output parameter and inputting a multi-output model yields the following error:
~/.local/lib/python3.6/site-packages/talos/scan/scan_prepare.py in scan_prepare(self)
57
58 # create the data asset
---> 59 self.y_max = self.y.max()
60 self = validation_split(self)
61 self.shape = classify(self.y)
AttributeError: 'list' object has no attribute 'max'
For example the model I am currently working with outputs Age, Species, and Status where each has a different value of c in the shape (m, c).
The text was updated successfully, but these errors were encountered: