-
Notifications
You must be signed in to change notification settings - Fork 19.5k
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
Sample Weight Error #7120
Comments
Got the same error without even any weighting of samples |
Seems like a bug when the traceback says that it found a variable with inappropriate size, but Keras created this variable somewhere inside the call of |
I found out that my generator yielded third output that I used as a mask, but Keras used it as a |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 30 days if no further activity occurs, but feel free to re-open a closed issue if needed. |
I also had the same problem and I struggled with for a week. then it clicked with me and I made it work.
|
@Anesouadou I have a similar problem. Your suggestion didn't work :(. If I make my label/sample weight 3D i.e., (batch, 3920, 1) and set sample_weight_mode to 'temporal' I get the following error: ValueError: Found a sample_weight array with shape (None, 3920, 1). In order to use timestep-wise sample weighting, you should pass a 2D sample_weight array. When I flatten the labels/sample_weights I then get this error: ValueError: Found a sample_weight array for an input with shape (None, 3920). Timestep-wise sample weighting (use of sample_weight_mode="temporal") is restricted to outputs that are at least 3D, i.e. that have a time dimension. It's contradicting itself! |
@wmcnally I think you are confusing the correct format for each parameter.
|
@Anesouadou oh, ok. So in that case, the shape of the 2D sample weight should be (number of samples, flattened sample), correct? Thanks in advance for your help. |
@wmcnally yes, it should work just fine. Let me how it goes. |
@Anesouadou I got it working. Thanks so much for the help. |
How did you resolve this. I am facing same issue with same type of data type. I have embeddings, mask and labels as output from data generator. I really appreciate your help on this. Thanks |
Hi there!
I'm working on a brain lesion segmentation problem and I'm trying to implement a Unet with code inspired by: https://github.com/jocicmarko/ultrasound-nerve-segmentation
One of the issues I'm trying to overcome is class balance (lots more non-lesion voxels rather than lesion voxels). I tried using class_balance but that didn't work so now I'm trying to use sample_weight and that's also giving me all sorts of errors.
i) First thing I tried was to set sample_weight_mode to 'temporal' and feed in a weight matrix of the same shape as my target data:
target_data.shape -> (n_samples,512 rows/pixels, 512 cols/pixels, 1 channel )
Weight_map.shape -> (n_samples,512 rows/pixels, 512 cols/pixels, 1 channel )
output:
_ValueError: Found a sample_weight array with shape (100, 512, 512, 1). In order to use timestep-wise sample weighting, you should pass a 2D sample_weight array.
ii) Second thing I tried was to flatten the sample array so it would be of shape:
Weight_map.shape -> (n_samples,512x512x1).
output:
ValueError: Found a sample_weight array with shape (100, 262144) for an input with shape (100, 512, 512, 1). sample_weight cannot be broadcast.
iii) Next I tried following the advice of uschmidt83 (here) and flattening the output of my model along with the corresponding target data.
last_layer = keras.layers.Flatten()(second_last_layer)
target_data.shape -> (n_samples,512x512x1).
Weight_map.shape -> (n_samples,512x512x1).
output:
ValueError: Found a sample_weight array for an input with shape (100, 262144). Timestep-wise sample weighting (use of sample_weight_mode="temporal") is restricted to outputs that are at least 3D, i.e. that have a time dimension.
Oddly enough, even if I set sample_weight=None I still get the same error as right above.
Any advice on how to fix this sample_weight error? Here is the basic code to reproduce the error
here
Also, if you have advice about how to deal the class imbalance problem, please let me know.
The text was updated successfully, but these errors were encountered: