Skip to content

Instantly share code, notes, and snippets.

View sadimanna's full-sized avatar
🏠
Working from home

Siladittya Manna sadimanna

🏠
Working from home
View GitHub Profile
reg_loss = 0
for mod in self.model.modules():
if isinstance(mod, _BatchNorm):
if self.decay_bn:
for name, param in mod.named_parameters(recurse=False):
reg_loss = reg_loss + param.norm(2)
else:
for name, param in mod.named_parameters(recurse=False):
if not name.endswith("bias"):
reg_loss = reg_loss + param.norm(2)
@tf.keras.saving.register_keras_serializable(name="weighted_categorical_crossentropy")
def weighted_categorical_crossentropy(target, output, weights, axis=-1):
target = tf.convert_to_tensor(target)
output = tf.convert_to_tensor(output)
target.shape.assert_is_compatible_with(output.shape)
weights = tf.reshape(tf.convert_to_tensor(weights, dtype=target.dtype), (1,-1))
# Adjust the predictions so that the probability of
# each class for every sample adds up to 1
# This is needed to ensure that the cross entropy is
@tf.keras.saving.register_keras_serializable(name="weighted_binary_crossentropy")
def weighted_binary_crossentropy(target, output, weights):
target = tf.convert_to_tensor(target)
output = tf.convert_to_tensor(output)
weights = tf.convert_to_tensor(weights, dtype=target.dtype)
epsilon_ = tf.constant(tf.keras.backend.epsilon(), output.dtype.base_dtype)
output = tf.clip_by_value(output, epsilon_, 1.0 - epsilon_)
# Compute cross entropy from probabilities.
@tf.keras.saving.register_keras_serializable(name="WeightedCategoricalCrossentropy")
class WeightedCategoricalCrossentropy:
def __init__(
self,
weights,
label_smoothing=0.0,
axis=-1,
name="weighted_categorical_crossentropy",
fn = None,
):
@tf.keras.saving.register_keras_serializable(name="WeightedBinaryCrossentropy")
class WeightedBinaryCrossentropy:
def __init__(
self,
label_smoothing=0.0,
weights = [1.0, 1.0],
axis=-1,
name="weighted_binary_crossentropy",
fn = None,
):
@echo off
setlocal enabledelayedexpansion
REM Set the paths for the main image folder, train folder, val folder, and test folder
set "image_folder=C:\Path\to\ImageFolder"
set "train_folder=C:\Path\to\train"
set "val_folder=C:\Path\to\val"
set "test_folder=C:\Path\to\test"
REM Create the train, val, and test folders if they don't exist
REM Set the paths for Folder A, train folder, val folder, and test folder
set "mask_folder_path=%base_path%\annotations\trimaps"
set "train_mask_path=%base_path%\train_masks"
REM Create the target folder if it doesn't exist
mkdir "%train_mask_path%"
set "extension=.EXT"
REM Move label files from the label folder to the train folder based on file names
for %%F in ("%train_image_path%\*") do (
set "file_name=%%~nF"
move "%mask_folder_path%\!file_name!%extension%" "%train_mask_path%\"
@echo off
setlocal enabledelayedexpansion
REM Set the paths for Folder A, train folder, val folder, and test folder
set "base_path=C:\Users\ISI_UTS\Siladittya\MIDA2023"
set "image_folder_path=%base_path%\images"
set "train_image_path=%base_path%\train_images"
set "val_image_path=%base_path%\val_images"
set "test_image_path=%base_path%\test_images"
#!/bin/bash
# Set the paths for the train folder, label folder, and target folder
train_folder_path="/path/to/train"
label_folder_path="/path/to/label"
target_folder_path="/path/to/target"
label_ext = ".labext"
# Create the target folder if it doesn't exist
mkdir -p "$target_folder_path"
#!/bin/bash
# Set the paths for Folder A and the three target folders
folder_a_path="/path/to/FolderA"
train_folder_path="/path/to/train"
val_folder_path="/path/to/val"
test_folder_path="/path/to/test"
# Create the target folders if they don't exist
mkdir -p "$train_folder_path"