Пример #1
0
# Print out a summary of the model you created
model.summary()

# ### Congratulations! You've created your very own U-Net model architecture!
# Next, you'll check that you did everything correctly by comparing your model summary to the example model defined below.
#
# ### Double check your model
#
# To double check that you created the correct model, use a function that we've provided to create the same model, and check that the layers and the layer dimensions match!

# In[21]:

# Import predefined utilities
import util

# In[22]:

# Create a model using a predefined function
model_2 = util.unet_model_3d(depth=2,
                             loss_function='categorical_crossentropy',
                             metrics=['categorical_accuracy'])

# In[23]:

# Print out a summary of the model created by the predefined function
model_2.summary()

# #### Look at the model summary for the U-Net you created and compare it to the summary for the example model created by the predefined function you imported above.

# #### That's it for this exercise, we hope this have provided you with more insight into the network architecture you'll be working with in this week's assignment!
Пример #2
0
    print(label[0, :, :, 0])

    dc = soft_dice_loss(pred, label, epsilon=1)
    print(f"soft dice loss: {dc.eval():.4f}")

# <a name="4"></a>
# # 4 Create and Train the model
#
# Once you've finished implementing the soft dice loss, we can create the model!
#
# We'll use the `unet_model_3d` function in `utils` which we implemented for you.
# - This creates the model architecture and compiles the model with the specified loss functions and metrics.

# In[26]:

model = util.unet_model_3d(loss_function=soft_dice_loss,
                           metrics=[dice_coefficient])

# In[27]:

# run this cell if you didn't run the training cell in section 4.1
base_dir = HOME_DIR + "processed/"
with open(base_dir + "config.json") as json_file:
    config = json.load(json_file)
# Get generators for training and validation sets
train_generator = util.VolumeDataGenerator(config["train"],
                                           base_dir + "train/",
                                           batch_size=3,
                                           dim=(160, 160, 16),
                                           verbose=0)
valid_generator = util.VolumeDataGenerator(config["valid"],
                                           base_dir + "valid/",