Categories
Misc

Network Guesses Very Similar For All Inputs

I have an image classification neural network that is designed for multi-label classification, I am using multi-hot encoded data, and a data generator that reads image files off of my hard drive. all images have been resized into the range of 96×96 (keeping aspect ratio (Also I have the same data in many other sizes)), and all color values have been divided by 255, although I have thought of switching that to 127.5 and then subtract 1. my learning algorithm is Adam with a learning rate of 0.0001. I am using binary crossentropy as my loss function. I have approx. 147,000 images in my data set, and my goal is to correctly classify 150 tags, (although I have access to over 500). my classes are highly imbalanced, however I have been applying weights (I’ve been using the class_weight parameter to administer my weights) and my model looks like this :

model = Sequential([ Input(shape=(None, None,3)), experimental.preprocessing.RandomRotation(0.2), Conv2D(4,(7,7),activation='relu'), MaxPooling2D(pool_size=(2,2)), Conv2D(4,(7,7),activation='relu'), Conv2D(4,(5,5),activation='relu'), Conv2D(4,(5,5),activation='relu'), Conv2D(8,(5,5),activation='relu'), Conv2D(16,(5,5),activation='relu'), Conv2D(32,(3,3),activation='relu'), Conv2D(64,(3,3),activation='relu'), Conv2D(128,(3,3),activation='relu'), Conv2D(256,(3,3),activation='relu'), Conv2D(256,(3,3),activation='relu'), GlobalMaxPooling2D(), Flatten(), Dropout(0.4), Dense(256,activation='relu'), Dense(256,activation='relu'), Dropout(0.2), Dense(256,activation='relu'), Dense(len(classes), activation='sigmoid') ]) 

I have tried alternate last layer activation functions, to no avail. I have also decreased the number of convolutional layers, decreased the number of dense layers, increased the number of dense layers, increased learning rate, decreased learning rate, I even played around with different weight values. Just writing this has given me insight into the workings of my network, and I may have an idea as to what the issue is, however I would like to hear any untainted suggestions, and recommendations. Any tips for general performance enhancements and the like would also be greatly appreciated.

Edit 1 : I’ve attempted a custom weighted binary crossentropy loss function that has worked for other models in the past, however, it is now throwing an error. here is the loss function

def get_weighted_loss(weights): def weighted_loss(y_true, y_pred): return K.mean((weights[:,0]**(1-y_true))*(weights[:,1]**(y_true))*K.binary_crossentropy((y_true), y_pred), axis=-1) return weighted_loss 

and the error is this

Traceback (most recent call last): File "C:Userscws72tensorflowProjectsMulti-Label-Training-V5.py", line 163, in <module> history = model.fit(train_data.padded_batch(BATCH_SIZE).prefetch(tf.data.AUTOTUNE).repeat(), File "C:Userscws72anaconda3envsTensorflow-GPU-WorkDirlibsite-packageskerasenginetraining.py", line 1158, in fit tmp_logs = self.train_function(iterator) File "C:Userscws72anaconda3envsTensorflow-GPU-WorkDirlibsite-packagestensorflowpythoneagerdef_function.py", line 889, in __call__ result = self._call(*args, **kwds) File "C:Userscws72anaconda3envsTensorflow-GPU-WorkDirlibsite-packagestensorflowpythoneagerdef_function.py", line 933, in _call self._initialize(args, kwds, add_initializers_to=initializers) File "C:Userscws72anaconda3envsTensorflow-GPU-WorkDirlibsite-packagestensorflowpythoneagerdef_function.py", line 763, in _initialize self._stateful_fn._get_concrete_function_internal_garbage_collected( # pylint: disable=protected-access File "C:Userscws72anaconda3envsTensorflow-GPU-WorkDirlibsite-packagestensorflowpythoneagerfunction.py", line 3050, in _get_concrete_function_internal_garbage_collected graph_function, _ = self._maybe_define_function(args, kwargs) File "C:Userscws72anaconda3envsTensorflow-GPU-WorkDirlibsite-packagestensorflowpythoneagerfunction.py", line 3444, in _maybe_define_function graph_function = self._create_graph_function(args, kwargs) File "C:Userscws72anaconda3envsTensorflow-GPU-WorkDirlibsite-packagestensorflowpythoneagerfunction.py", line 3279, in _create_graph_function func_graph_module.func_graph_from_py_func( File "C:Userscws72anaconda3envsTensorflow-GPU-WorkDirlibsite-packagestensorflowpythonframeworkfunc_graph.py", line 999, in func_graph_from_py_func func_outputs = python_func(*func_args, **func_kwargs) File "C:Userscws72anaconda3envsTensorflow-GPU-WorkDirlibsite-packagestensorflowpythoneagerdef_function.py", line 672, in wrapped_fn out = weak_wrapped_fn().__wrapped__(*args, **kwds) File "C:Userscws72anaconda3envsTensorflow-GPU-WorkDirlibsite-packagestensorflowpythonframeworkfunc_graph.py", line 986, in wrapper raise e.ag_error_metadata.to_exception(e) StagingError: in user code: C:Userscws72anaconda3envsTensorflow-GPU-WorkDirlibsite-packageskerasenginetraining.py:830 train_function * return step_function(self, iterator) C:Userscws72anaconda3envsTensorflow-GPU-WorkDirlibsite-packageskerasenginetraining.py:813 run_step * outputs = model.train_step(data) C:Userscws72anaconda3envsTensorflow-GPU-WorkDirlibsite-packageskerasenginetraining.py:771 train_step * loss = self.compiled_loss( C:Userscws72anaconda3envsTensorflow-GPU-WorkDirlibsite-packageskerasenginecompile_utils.py:201 __call__ * loss_value = loss_obj(y_t, y_p, sample_weight=sw) C:Userscws72anaconda3envsTensorflow-GPU-WorkDirlibsite-packageskeraslosses.py:142 __call__ * losses = call_fn(y_true, y_pred) C:Userscws72anaconda3envsTensorflow-GPU-WorkDirlibsite-packageskeraslosses.py:246 call * return ag_fn(y_true, y_pred, **self._fn_kwargs) C:Userscws72tensorflowProjectsMulti-Label-Training-V5.py:24 weighted_loss * return K.mean((weights[:,0]**(1-y_true))*(weights[:,1]**(y_true))*K.binary_crossentropy((y_true), y_pred), axis=-1) IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed 

submitted by /u/Yo1up
[visit reddit] [comments]

Leave a Reply

Your email address will not be published. Required fields are marked *