AI-CAMP四期作业贴:【AI培训第四期课后作业内容帖】
week1 【AI培训第四期课后作业内容帖】
week2 【AI培训第四期课后作业内容帖】
week3 【AI培训第四期课后作业内容帖】
week4 【AI培训第四期课后作业内容帖】
week5 【AI培训第四期课后作业内容帖】
week6 【AI培训第四期课后作业内容帖】
最终实践作业 【AI培训第四期课后作业内容帖】
AI-CAMP4期实践作业帖 【AI-CAMP 四期实践项目汇总】
AI-CAMP四期作业贴:【AI培训第四期课后作业内容帖】
week1 【AI培训第四期课后作业内容帖】
week2 【AI培训第四期课后作业内容帖】
week3 【AI培训第四期课后作业内容帖】
week4 【AI培训第四期课后作业内容帖】
week5 【AI培训第四期课后作业内容帖】
week6 【AI培训第四期课后作业内容帖】
最终实践作业 【AI培训第四期课后作业内容帖】
AI-CAMP4期实践作业帖 【AI-CAMP 四期实践项目汇总】
[ ASSIGNMENT ]
CIFAR10 ResNet : git_ai_train_liliming_week4_resnet_cifar10
[Epoch 199] loss: 0.1366770236729047
correct: 8655, total: 10000, accuracy: 86.55%
Inflatable arch - Group1 OwnData :git_ai_train_liliming_week4_resnet_arch_self
epoch 39 Step 31900, LR 0.0013, Loss 0.113 (0.254) Acc@1 100.000 (88.750) Time 0.068 (0.069)
Test step 0, Loss 0.112 (0.112) Acc@1 100.000 (100.000) Acc@2 100.000 (100.000) Time 0.465 (0.465)
megstudio submitted
[Detection] Inflatable Arch - Group1 OwnData :
git :git_ai_train_liliming_week5_retinanet
Traing:
[Detection] Inflatable Arch - Group1 OwnData :
git :git_ai_train_liliming_week7
MegFlow:
通过 MegStudio 提交 项目详情 | MegStudio (brainpp.com)
爬虫爬取拱门数据/Microsoft Edge的Download All Imageschaj
def get_images(query, n, path):
iters = math.ceil(n / 100)
left = n
for it in range(iters):
start = it * 100
num = min(left, 100)
req = ‘https://pic.sogou.com/napi/pc/searchList?mode=2&cwidth=1440&cheight=900&dm=4&query=’ + query + ‘&start=’ + str(
start) + ‘&xml_len=’ + str(num)
imgs = requests.get(req)
jd = json.loads(imgs.text)
jd = jd[‘data’][‘items’]
img_urls = [j[‘oriPicUrl’] for j in jd]
# img_urls = [j[‘thumbUrl’] for j in jd]
print(“len:”, len(img_urls))
for i in range(len(img_urls)):
try:
img_url = img_urls[i]
save_path = path + str(start + i) + ‘.jpg’
print(‘Downloading {} from url: {}’.format(save_path, img_url))
urllib.request.urlretrieve(img_url, save_path)
except Exception as e:
print(e)
left -= num
print(‘Download finish!’)
if name == ‘main’:
get_images(‘拱门’, 1000, ‘E:\Study\AI\ch3\data’)
通过 MegStudio 提交 项目详情 | MegStudio (brainpp.com)
通过 MegStudio 提交 项目详情 | MegStudio (brainpp.com)
import os
import cv2
import numpy as np
from imgaug import augmenters as iaa
#加载图片
def read_img(file_dir):
L=
for root, dirs, files in os.walk(file_dir):
for file in files:
if os.path.splitext(file)[1] == ‘.jpeg’:
img_mat = cv2.imread(os.path.join(root, file));
L.append(img_mat)
return L
def get_img_statistics(img_list):
img_size_list =
for i, img in enumerate(img_list):
img_size_list.append({“img_num”: “img_{}”.format(i), “height”: img.shape[0], “width”: img.shape[1]})
height_list = [img_size["height"] for img_size in img_size_list]
width_list = [img_size['width'] for img_size in img_size_list]
avg_height = np.mean(height_list)
max_height = max(height_list)
min_height = min(height_list)
avg_width = np.mean(width_list)
max_width = max(width_list)
min_width = min(width_list)
img_info = {'avg_height': avg_height, 'max_height': max_height, 'min_height': min_height,
'avg_width': avg_width, 'max_width': max_width, 'min_width': min_width,
'img_size': img_size_list}
print("图片信息统计结果: {}".format(img_info))
return img_info
def enhance_img(img_list):
H, W = 128, 128
NUM = 6
seq = iaa.Sequential([
iaa.Fliplr(0.5), # 图像的50%概率水平翻转
iaa.Crop(percent=(0, 0.05)), # 四边以0 - 0.05之间的比例像素剪裁
iaa.Affine(
scale={"x": (0.8, 1.2), "y": (0.8, 1.2)}, # 图像缩放
translate_px={"x": (-16, 16), "y": (-16, 16)}, # 像素随机平移
rotate=(-45, 45) # 旋转-45度或45度
),
iaa.GaussianBlur(sigma=(0, 5.0)), # 高斯模糊
iaa.Resize({"height": H, "width": W})
], random_order=True)
res = np.zeros(shape=((H + 10) * len(images), (W + 10) * NUM, 3), dtype=np.uint8)
for i, img in enumerate(img_list):
img_array = np.array([img] * NUM, dtype=np.uint8)
write_img = np.zeros(shape=(H, (W + 10) * NUM, 3), dtype=np.uint8)
images_aug = seq.augment_images(images=img_array)
for j, item in enumerate(images_aug):
write_img[:, j * (W + 10): j * (W + 10) + W, :] = item
# 结果写在一张图片里
res[i * (H + 10): i * (H + 10) + H, :, :] = write_img
cv2.imwrite("data/result.jpg", res)
if name == “main”:
images = read_img("./data")
get_img_statistics(images)
enhance_img(images)
基础作业:由于mnist使用megengine,所以基础作业使用numpy实现线性拟合,在拟合的过程中,发现由于生成的是随机数,所以每次需要的拟合次数不同,设置了30次的拟合次数
最终第30次的拟合结果:
通过 MegStudio 提交
https://studio.brainpp.com/project/10957?name=AI培训课后作业(3_4)_huangziqun_作业
已提交到 git-core
https://git-core.megvii-inc.com/ai_train/ai-huangziqun/-/tree/master
已在MegStudio环境中提交
https://studio.brainpp.com/project/10460?name=AI%E5%9F%B9%E8%AE%AD%E8%AF%BE%E5%90%8E%E4%BD%9C%E4%B8%9A%284_2%29_MGXiejisheng_%E4%BD%9C%E4%B8%9A
作业已在Studio环境中提交
https://studio.brainpp.com/project/10950?name=AI培训课后作业(3_4)_MGXiejisheng_作业
https://git-core.megvii-inc.com/shixiaopeng/ai_camp_4th/-/blob/master/homework03/hw3.py
文档作业见lable++平台: https://www.zzcrowd.com/requirement/index.html#/requirement-mgmt/requirement-application?uid=ae49cc6ae2e1bab5
2021-0824 从第七转入第一大组.
cifar-10: https://git-core.megvii-inc.com/shixiaopeng/ai_camp_4th/-/blob/master/homework04/train-cifar-10.py
结果: batch_size=256,epoch = 200, loss: 0.09, acc: 87.64%
拱门: https://git-core.megvii-inc.com/shixiaopeng/ai_camp_4th/-/blob/master/homework04/train-archway.py
结果: batch_size=8,epoch = 40, loss: 0.102, acc: 87.5%
第二周作业
import numpy as np
import matplotlib.pyplot as plt
import megengine as mge
import megengine.functional as F
from megengine.autodiff import GradManager
import megengine.optimizer as optim
def generate_random_examples(n=100, noise=5):
w = np.random.randint(5, 10)
b = np.random.randint(-10, 10)
print(“The real w: {}, b:{}”.format(w, b))
data = np.zeros((n,))
label = np.zeros((n,))
for i in range(n):
data[i] = np.random.uniform(-10, 10)
label[i] = w * data[i] + b + np.random.uniform(-noise, noise)
plt.scatter(data[i], label[i], marker=".")
plt.plot()
plt.show()
return data, label
original_data, original_label = generate_random_examples()
epochs = 10
lr = 0.01
data = mge.tensor(original_data)
label = mge.tensor(original_label)
w = mge.Parameter([0.0])
b = mge.Parameter([0.0])
def linear_model(x):
return F.mul(w, x) + b
gm = GradManager().attach([w, b])
optimizer = optim.SGD([w, b], lr = lr)
for epoch in range(epochs):
with gm:
pred = linear_model(data)
loss = F.loss.square_loss(pred, label)
gm.backward(loss)
optimizer.step().clear_grad()
print("epoch = {}, w = {:.3f}, b = {:.3f}, loss = {:.3f}".
format(epoch, w.item(), b.item(), loss.item()))
x = np.array([-10, 10])
y = w.numpy() * x + b.numpy()
plt.scatter(data, label, marker=".")
plt.plot(x, y, “-b”)
plt.show()