Я работаю над обнаружением и идентификацией поражений кожи с использованием предварительно обученной сети Dens enet. Однако я застрял в этой проблеме, где говорится, что веса не могут быть переданы значениям.
```
%tensorflow_version 1.x
import tensorflow as tf
from tensorflow.keras.applications import densenet
from tensorflow.keras import layers
from tensorflow.keras.models import Sequential,Model,load_model
from tensorflow.keras.layers import Convolution2D
from tensorflow.keras.layers import MaxPooling2D
from tensorflow.keras.layers import Flatten,Dense,Activation,Dropout
from tensorflow.keras.callbacks import EarlyStopping,ReduceLROnPlateau,ModelCheckpoint,Callback
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.models import Model
image_width,image_height=224,224 #Assigning height and width ---Densenet is trained in 224*224 dimensions
training_samples = 33068 #No of training sample
testing_samples = 1103 #Number of validation sample
epochs = 100
batch_size = 10 #Taking the batch_size of 10
n_classes = 7 #Number of classes is 7. We have 7 categories of skin disease
training_folder = '/content/gdrive/My Drive/Deep Learning Projects/skincancer/skin_cancer_classified/training_directory/'
testing_folder = '/content/gdrive/My Drive/Deep Learning Projects/skincancer/skin_cancer_classified/testing_directory/'
datagen = ImageDataGenerator(
preprocessing_function= \
tf.keras.applications.densenet.preprocess_input)
#Using the same pre processing technique that was applied to the original rgb images for densenet architecture
training_batches = datagen.flow_from_directory(training_folder,
target_size=(image_height,image_width),
batch_size = batch_size)
testing_batches = datagen.flow_from_directory(testing_folder,
target_size=(image_height,image_width),
batch_size = batch_size)
network = tf.keras.applications.densenet.DenseNet121()
######Creating the model architecture by removing the last 5 layers from the network
engineered_network = network.layers[-5].output
engineered_network = Dropout(0.25)(engineered_network)
predictions = Dense(7,activation='softmax')(engineered_network)
final_model = Model(inputs = network.input, outputs = predictions)
for layer in final_model.layers[:-30]:
layer.trainable = False
final_model.compile(optimizer='Adam',loss='categorical_crossentropy',metrics=["accuracy"])
class_weights = {
0: 1.0,
1: 1.0,
2: 1.0,
3: 1.0,
4: 3.2, #making melanoma more sensitive
5: 1.0,
6: 1.0,
}
network_training = final_model.fit_generator(training_batches,
steps_per_epoch=36,
class_weight=class_weights,
validation_data = testing_batches,
validation_steps = 110,
epochs=epochs,
verbose = 1)
```
Я получаю эту ошибку:
#############################################
Epoch 1/100
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-16-6a6e3a644f6a> in <module>()
5 validation_steps = 110,
6 epochs=epochs,
----> 7 verbose = 1)
11 frames
/tensorflow-1.15.2/python3.6/tensorflow_core/python/ops/weights_broadcast_ops.py in assert_broadcastable(weights, values)
101 " values.shape=%s. weights.shape=%s." % (
102 _ASSERT_BROADCASTABLE_ERROR_PREFIX, values_rank_static,
--> 103 weights_rank_static, values.shape, weights.shape))
104 weights_shape_static = tensor_util.constant_value(weights_shape)
105 values_shape_static = tensor_util.constant_value(values_shape)
ValueError: weights can not be broadcast to values. values.rank=3. weights.rank=1. values.shape=(?, 7, 7). weights.shape=(?,).
У меня не было практики в использовании предварительно обученной сети, так что это ново для меня. Любая помощь будет оценена. Спасибо