<jupyter_start><jupyter_text>⚔Fast.ai中的尝试       Fast.ai Version: v2.0.17  Draft Date: 2020-06-09           记录`fast.ai` 使用中的一些尝试 ...<jupyter_code>from fastai.vision.all import *<jupyter_output><empty_output><jupyter_text>标记 提示💡: 蓝色给大家一些新的提示要点，可以进行拓展操作.    经验分享👣分享一些经验，踩过的坑.    知识回顾📕: 这部分会对学过的知识进行关联和回顾，便于大家进行巩固.     概要✅：绿色部分为章节内容核心点，提醒关注.   重要📌    红色标识了重点注意事项，提醒大家注意.    🤔--这是被隐藏的内容，思考之后再打开👇>>打开之后你将看到内容的详情 ...>>  自定义Transforms<jupyter_code>def centerSizeCrop(image, crop_size):
    rows, cols = image.shape[:2]
    x = round((cols - crop_size) / 2.0)
    y = round((rows - crop_size) / 2.0)
    img = image[y:y+crop_size, x:x+crop_size]
    return img
def fixsizeCrop(img, size,crop):
    img = cv2.cvtColor(np.asarray(img),cv2.COLOR_RGB2BGR)
    img = cv2.resize(img, size)
    img = centerSizeCrop(img, crop)
    return Image.fromarray(cv2.cvtColor(img,cv2.COLOR_BGR2RGB)) 
class SizeTfm(Transform):
    def __init__(self,size,crop):
        if isinstance(size,int): size=(size,size)
        self.size = size
        self.crop = crop
    def encodes(self, img: Image.Image):
        return fixsizeCrop(img, self.size,self.crop)
path = untar_data(URLs.PETS)
files = get_image_files(path/'images')
img = PILImage.create(files[0])
img
img.size
SizeTfm((500,333),320)(img)<jupyter_output><empty_output><jupyter_text>如何获取validation sets的一个批数据<jupyter_code>path = untar_data(URLs.PETS)
files = get_image_files(path/"images")
def label_func(f): return f[0].isupper()
data = ImageDataLoaders.from_name_func(path, files, label_func, item_tfms=Resize(224))
with data.valid.fake_l.no_multiproc():
    out = next(iter(data.valid))
out[0].shape, out[1].shape<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1449016100178891, 'fraction_numerical': 0.02385211687537269, 'mean_word_length': 4.726962457337884, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '513770', 'license': 'MIT', 'n_tokens_mistral': 815, 'n_tokens_neox': 829, 'n_words': 100, 'path': '3.fastai/01.EfficientNet.ipynb', 'repo_name': 'ddebby/AI-Lab', 'size': '1677'}