【AI-CAMP四期】第五组作业
lile第一周作业
代码
import matplotlib.pylab as plt
import numpy as np
from imgaug import augmenters as iaa
def img_aug(imgs):
seq = iaa.Sequential(
[
iaa.Crop(px=(0,16)),
iaa.Affine(
rotate=(-45, 45),
)
],
random_order=True
)
return seq.augment_images(imgs)
def unpickle(file):
import pickle
with open(file, ‘rb’) as fo:
dict = pickle.load(fo, encoding=‘bytes’)
return dict
def Getphoto(pixel):
assert len(pixel) == 3072
r = pixel[0:1024]; r = np.reshape(r, [32, 32, 1])
g = pixel[1024:2048]; g = np.reshape(g, [32, 32, 1])
b = pixel[2048:3072]; b = np.reshape(b, [32, 32, 1])
photo = np.concatenate([r, g, b], -1)
return photo
统计
def img_mean_max_min(np_array):
npa = np.array(np_array)
max_w = npa.max(axis=0)
min_h = npa.min(axis=0)
mean_w = npa.mean(axis=0)
mean_h = npa.mean(axis=0)
result_format = [max_w[0],min_h[1],mean_w[0],mean_h[1]]
print(“max_widht: {0}, max_height: {1},avg_widht: {2}, avg_height: {3}”.format(*result_format))
images =
images_shape =
for i in range(1, 1+5):
tmp = unpickle("./dataset/cifar-10-batches-py/data_batch_%d"%i)[b’data’]
a = np.random.choice(a=1000, size=3, replace=False, p=None)
for i in tmp[a]:
img = Getphoto(i)
images.append(img)
#print (img.shape)
images_shape.append(img.shape)
img_mean_max_min(images_shape)
auged_imgs = img_aug(images)
for i in range(len(auged_imgs)):
work3_1 = np.concatenate((images[i], auged_imgs[i]), axis=1)
plt.imshow(work3_1)
plt.show()
统计信息
结果输出
第一周作业
https://studio.brainpp.com/project/9943?name=AI培训课后作业(3_1)_weierpeng_作业
第二周作业
https://studio.brainpp.com/project/10449?name=AI培训课后作业(3_2)_weierpeng_作业
高江峰作业
第一周作业
统计信息 :
----| max: 32, 32
----| min: 32, 32
----| avg: 32.0, 32.0
----| cnt: 9
截图 :
第二周作业
王迪第一周作业
统计信息:
(10, 32, 32, 3)
图片信息统计结果: {‘avg_height’: 32, ‘avg_width’: 32}
图片信息统计结果: {‘avg_height’: 32, ‘avg_width’: 32}
图片信息统计结果: {‘avg_height’: 32, ‘avg_width’: 32}
图片信息统计结果: {‘avg_height’: 32, ‘avg_width’: 32}
图片信息统计结果: {‘avg_height’: 32, ‘avg_width’: 32}
图片信息统计结果: {‘avg_height’: 32, ‘avg_width’: 32}
图片信息统计结果: {‘avg_height’: 32, ‘avg_width’: 32}
图片信息统计结果: {‘avg_height’: 32, ‘avg_width’: 32}
图片信息统计结果: {‘avg_height’: 32, ‘avg_width’: 32}
图片信息统计结果: {‘avg_height’: 32, ‘avg_width’: 32}
效果结果:
赵玺第三周作业
![import re
import requests
header = {
‘User-Agent’: ‘Mozilla/5.0(Windows NT 5.1) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.84 Safari/535.11 SE 2.X MetaSr 1.0’,
‘Referer’: ‘https://image.baidu.com’
}
keyword_encode = “城市道路的充气拱门”
def get_images(total_num, keyword_encode=keyword_encode, start_num=1):
n = start_num
start_num = start_num
page_num = 30
img_set = set()
url = 'https://image.baidu.com/search/acjson?’
while True:
param = {
'tn': 'resultjson_com',
'logid': '8846269338939606587',
'ipn': 'rj',
'ct': '201326592',
'is': '',
'fp': 'result',
'queryWord': keyword_encode,
'cl': '2',
'lm': '-1',
'ie': 'utf-8',
'oe': 'utf-8',
'adpicid': '',
'st': '-1',
'z': '',
'ic': '',
'hd': '',
'latest': '',
'copyright': '',
'word': keyword_encode,
's': '',
'se': '',
'tab': '',
'width': '',
'height': '',
'face': '0',
'istype': '2',
'qc': '',
'nc': '1',
'fr': '',
'expermode': '',
'force': '',
'cg': 'girl',
'pn': start_num,
'rn': page_num,
'gsm': '1e',
}
res = requests.get(url=url, headers=header, params=param)
res.encoding = 'utf-8'
try:
res_data = res.json(strict=False)['data']
for img_url in res_data:
img_url = img_url.get('thumbURL')
if not img_url:
continue
if n > total_num:
print(f"Finished: Totally download {n - 1} images.")
return
if img_url in img_set:
print('重复')
continue
img_set.add(img_url)
download_img(img_url, n)
n += 1
except Exception as e:
print(e)
finally:
start_num += page_num - 1
def download_img(img_url, num):
print(f"Downloading image {num}: {img_url}")
img = requests.get(img_url)
with open(‘image/{}.jpg’.format(num), ‘wb’) as f:
f.write(img.content)
if name == ‘main’:
get_images(1000, start_num=986)]
没有修改权限了,第二周作业无法提交