This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
#### -- ------------------------------------------- 多张图片写入一个 tfrecord, 整个数据集写入多个 tfrecord ------------------ | |
# 其中 max_files 为每个shard 分片 写入文件数量, images 为全部图片列表 | |
splits = (len(images)//max_files) + 1 | |
for i in range(splits): | |
# filename 为当前shard保存的文件名,out_dir 全部tfrecord 保存目录 | |
current_shard_name = "{}{}_{}{}.tfrecords".format(out_dir, i+1, splits, filename) | |
# 为 每个 分片 shard 创建一个写 | |
writer = tf.io.TFRecordWriter(current_shard_name) | |
current_shard_count = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tensorflow.keras.models import Model | |
from tensorflow.keras.applications import VGG16 | |
from tensorflow.keras.layers import Dense, GlobalAveragePooling2D | |
from tensorflow.keras.preprocessing.image import ImageDataGenerator | |
# ImageDataGenerator | |
train_datagen = ImageDataGenerator( | |
horizontal_flip=True, | |
vertical_flip=True, | |
rotation_range=50, | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
def get_timestr_perday_by_range(from_time,to_time): | |
''' | |
计算一段时间内 有多少天,以及每天的时间区间。如果起止时间超过1天,默认新增的一天会从 00:00:00到23:59:59 | |
:param from_time: | |
:param to_time: | |
:return: | |
''' | |
range_timestr_tuples = [] | |
# 计算两个时间的时间差 |