Skip to content

Commit

Permalink
include the Apache license header for process_data.py
Browse files Browse the repository at this point in the history
  • Loading branch information
NLGithubWP committed Jul 9, 2021
1 parent c115d3b commit 3d0d574
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions examples/largedataset_cnn/process_data.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#

import os
import imghdr
import numpy as np
Expand All @@ -10,15 +29,15 @@ def paths_to_images(paths, image_size):
for i in range(num_images):
temp = np.array(Image.open(paths[i]).convert('RGB').resize((image_size, image_size), Image.BILINEAR))
temp = np.moveaxis(temp,-1,0)
im[i] = temp
im[i] = temp

im /= 255

return im


def process_data(dataset_root, classes):
# load class names
# load class names
with open(classes, 'r', encoding='utf-8') as f:
classes = f.readlines()
classes = list(map(lambda x: x.strip(), classes))
Expand Down Expand Up @@ -52,16 +71,16 @@ def process_data(dataset_root, classes):
val_labels = labels[border:]
train_input_paths = input_paths[:border]
val_input_paths = input_paths[border:]


print("Training on %d images and labels" % (len(train_input_paths)))
print("Validation on %d images and labels" % (len(val_input_paths)))

return train_input_paths, train_labels, val_input_paths, val_labels

def loaddata():
dataset_root = '/Dataset/Data/'
classes = '/Dataset/classes.txt'
classes = '/Dataset/classes.txt'
return process_data(dataset_root, classes)

if __name__ == '__main__':
Expand All @@ -72,9 +91,8 @@ def loaddata():
print(train_input_paths.shape)
print(train_labels.shape)
print(val_input_paths.shape)
print(val_labels.shape)
print(val_labels.shape)

a=paths_to_images(paths=train_input_paths[0:5], image_size=299)
print(a)
print(a.shape)

0 comments on commit 3d0d574

Please sign in to comment.