itakura-2024-1-7 進捗報告
やったこと
train_net.py
code:train_net.py
# SummaryWriterの初期化
writer = SummaryWriter()
# write to tensorboard format if available.
if writer is not None:
# エポックごとの損失を保存
writer.add_scalar('Loss/Train', loss, cur_epoch*38+number)
print((sal_map * 255).to(torch.uint8))
モデルの出力を表示させてみた
code:dreyeve.py
import matplotlib.pyplot as plt
import torchvision.transforms.functional as F
# 画像保存先のディレクトリ
output_directory = "image"
os.makedirs(output_directory, exist_ok=True)
# ...
# TensorをPIL Imageに変換
pil_image = F.to_pil_image(sal_map)
# PIL ImageをMatplotlibで表示
plt.imshow(pil_image, cmap='gray')
plt.axis('off') # 軸を非表示にする
# 画像を保存
output_path = os.path.join(output_directory, "output_image.png")
plt.savefig(output_path, bbox_inches='tight', pad_inches=0)
# 表示
plt.show()
https://gyazo.com/8ea1e6b157e94df1cef949cce53cd9a5https://gyazo.com/40f04532bf2a6519683b5a1d158ca8eahttps://gyazo.com/9b58c0cae4fa999a1d50064380737829
code:default.py
# The mean value of the video raw pixels across the R G B channels.
# List of input frame channel dimensions.
_C.DATA.INPUT_CHANNEL_NUM = 3, 3 # The std value of the video raw pixels across the R G B channels.
code:utils.py
def tensor_normalize(tensor, mean, std):
"""
Normalize a given tensor by subtracting the mean and dividing the std.
Args:
tensor (tensor): tensor to normalize.
mean (tensor or list): mean value to subtract.
std (tensor or list): std to divide.
"""
if tensor.dtype == torch.uint8:
tensor = tensor.float()
tensor = tensor / 255.0
if type(mean) == list:
mean = torch.tensor(mean)
if type(std) == list:
std = torch.tensor(std)
return tensor
平均を引いて標準偏差で割ることは必要か
255で割るだけにするとlossが負になった