当前位置: 首页 > news >正文

李宏毅机器学习2022-HW8-Anomaly Detection

文章目录

  • Task
  • Baseline
  • Report
    • Question2
  • Code Link

Task

异常检测Anomaly Detection

在这里插入图片描述

将data经过Encoder,在经过Decoder,根据输入和输出的差距来判断异常图像。training data是100000张人脸照片,testing data有大约10000张跟training data相同分布的人脸照片(label 0),还有10000张不同分布的照片(anomaly, label 1),每张照片都是(64,64,3),.npy file

以训练集的前三张照片为例,auto-encoder的输入和输出如下:

在这里插入图片描述

Baseline

Auto-encoder model一共有五种模型

  • fcn: fully-connected network
  • cnn: convolutional network
  • VAE
  • Resnet
  • Multi-encoder autoencoder
    • encoder(fcn+fcn+fcn)+decoder(fcn)
    • encoder(cnn+cnn+cnn)+decoder(cnn)
    • encoder(fcn+fcn+conv)+decoder(fcn)

通过FCN+调节超参数的方式可以轻易的达到strong,Resnet也是但是Multi-encoder的方式表现并不好,也许是我处理方式有问题,具体代码可以参考GitHub中的文件

Report

Question2

Train a fully connected autoencoder and adjust at least two different element of the latent representation. Show your model architecture, plot out the original image, the reconstructed images for each adjustment and describe the differences.

import matplotlib.pyplot as plt
# sample = train_dataset[random.randint(0,100000)]
sample = train_dataset[0]
print("sample shape:{}".format(sample.size()))
sample = sample.reshape(1,3,64,64)model.eval()
with torch.no_grad():img = sample.cuda()# 只调整fcn中的latent representation的其中两维,其他模型都是正常输出if model_type in ['res']:output = model(img)output = decoder(output)print("res output shape:{}".format(output.size()))output = output[0] # 第一个重建图像,当然只有一个图像if model_type in ['fcn']:img = img.reshape(img.shape[0], -1)x = model.encoder(img)x[0][2] = x[0][2]*3output = model.decoder(x)print("fcn output shape:{}".format(output.size()))output = output.reshape(3,64,64)if model_type in ['vae']:output = model(img)print("vae output shape:{}".format(output.size()))output = output[0][0] # output[0]是重建后的图像,output[0][0]重建后的第一个图像if model_type in ['cnn']:output = model(img)[0]print("output shape:{}".format(output.size()))sample = sample.reshape(3,64,64)   # 创建画布
fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(5, 5))# plt sample image
axes[0].imshow(transforms.ToPILImage()((sample+1)/2)) #imshow的输入(H,W,C)
axes[0].axis('off')
axes[0].annotate('sample input', xy=(0.5, -0.15), xycoords='axes fraction',ha='center', va='center')
# plt output image
axes[1].imshow(transforms.ToPILImage()((output+1)/2))
axes[1].axis('off')
axes[1].annotate('sample output', xy=(0.5, -0.15), xycoords='axes fraction',ha='center', va='center')plt.show()

在这里插入图片描述

Code Link

具体代码在Github

相关文章:

  • java的匿名内部类和lambda表达式
  • C语言VS实用调试技巧
  • 隧道灯光远程控制系统的设计与实现(论文+源码)_kaic
  • Spring Boot 进阶-Spring Boot 开发第一个Web接口
  • Java集合框架与Lambda表达式实践指南(小白速看)
  • 大模型Agent开发框架对比:LangGraph/LlamaIndex/DIY
  • 7-1.Android SQLite 之 SQLiteDatabase 简单编码模板(SQLiteDatabase 使用、SQL 语句编写)
  • 工业缺陷检测——Windows 10本地部署AnomalyGPT工业缺陷检测大模型
  • 综合题第二题(路由器的配置)
  • 高考技术——pandas使用
  • FastGPT大模型介绍
  • Python面向对象基础:类属性
  • Vscode把全部‘def‘都收起来的快捷键
  • Mybatis中 #{} 和 ${} 的区别是什么?
  • 【RabbitMQ】RabbitMq消息丢失、重复消费以及消费顺序性的解决方案
  • 【React系列】如何构建React应用程序
  • Brief introduction of how to 'Call, Apply and Bind'
  • es6(二):字符串的扩展
  • javascript 哈希表
  • MD5加密原理解析及OC版原理实现
  • ReactNativeweexDeviceOne对比
  • Sublime text 3 3103 注册码
  • vuex 笔记整理
  • vue从入门到进阶:计算属性computed与侦听器watch(三)
  • 阿里云购买磁盘后挂载
  • 从地狱到天堂,Node 回调向 async/await 转变
  • 经典排序算法及其 Java 实现
  • 你真的知道 == 和 equals 的区别吗?
  • 如何合理的规划jvm性能调优
  • 如何在 Tornado 中实现 Middleware
  • 移动端 h5开发相关内容总结(三)
  • 好程序员web前端教程分享CSS不同元素margin的计算 ...
  • #565. 查找之大编号
  • #多叉树深度遍历_结合深度学习的视频编码方法--帧内预测
  • (C语言)球球大作战
  • (ZT)出版业改革:该死的死,该生的生
  • (安全基本功)磁盘MBR,分区表,活动分区,引导扇区。。。详解与区别
  • (附源码)spring boot北京冬奥会志愿者报名系统 毕业设计 150947
  • (附源码)springboot 个人网页的网站 毕业设计031623
  • (附源码)springboot美食分享系统 毕业设计 612231
  • (十) 初识 Docker file
  • (一)SpringBoot3---尚硅谷总结
  • (转载)Linux网络编程入门
  • *算法训练(leetcode)第四十七天 | 并查集理论基础、107. 寻找存在的路径
  • .desktop 桌面快捷_Linux桌面环境那么多,这几款优秀的任你选
  • .dwp和.webpart的区别
  • .NET 的静态构造函数是否线程安全?答案是肯定的!
  • .NET 简介:跨平台、开源、高性能的开发平台
  • .NET/C# 在 64 位进程中读取 32 位进程重定向后的注册表
  • .NET实现之(自动更新)
  • .sh 的运行
  • @modelattribute注解用postman测试怎么传参_接口测试之问题挖掘
  • @WebService和@WebMethod注解的用法
  • [ Algorithm ] N次方算法 N Square 动态规划解决
  • [ vulhub漏洞复现篇 ] Celery <4.0 Redis未授权访问+Pickle反序列化利用