diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml new file mode 100644 index 0000000000..c49b61b08d --- /dev/null +++ b/.github/workflows/pylint.yml @@ -0,0 +1,50 @@ +# Copyright 2021 The TensorFlow Authors. All Rights Reserved. +# +# Licensed 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. +# ============================================================================== + +name: PyLint +on: + pull_request: + paths: + - '**.py' + +permissions: + contents: read + +jobs: + build: + name: PyLint + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + - name: Get file changes + id: get_file_changes + uses: trilom/file-changes-action@v1.2.4 + with: + output: ' ' + - name: Report list of changed files + run: | + echo Changed files: ${{ steps.get_file_changes.outputs.files }} + - name: Set up Python 3.9 + uses: actions/setup-python@v5 + with: + python-version: "3.10" + - name: Install Python dependencies + run: | + python -m pip install --upgrade pip + pip install pylint==3.0.2 numpy wheel + - name: Run PyLint on changed files + run: | + echo "${{ steps.get_file_changes.outputs.files}}" | tr " " "\n" | grep ".py$" | xargs pylint diff --git a/Applications/VGG/Tensorflow/dataset.py b/Applications/VGG/Tensorflow/dataset.py index 2168948fd9..d7dd3c4ad6 100644 --- a/Applications/VGG/Tensorflow/dataset.py +++ b/Applications/VGG/Tensorflow/dataset.py @@ -1,27 +1,32 @@ -#!/usr/bin/env python -# SPDX-License-Identifier: Apache-2.0 -# -# Copyright (C) 2020 Jijoong Moon -# -# @file dataset.py -# @date 15 July 2020 -# @brief This is for mnist input generation -# @see https://github.com/nnstreamer/nntrainer -# @author Jijoong Moon -# @bug No known bugs except for NYI items -# -# +""" +SPDX-License-Identifier: Apache-2.0 + +Copyright (C) 2020 Jijoong Moon + +@file dataset.py +@date 15 July 2020 +@brief This is for mnist input generation +@see https://github.com/nnstreamer/nntrainer +@author Jijoong Moon +@bug No known bugs except for NYI items +""" + import struct -import os import numpy as np -TOTAL_TRAIN_DATA_SIZE=100 -TOTAL_LABEL_SIZE=100 -TOTAL_VAL_DATA_SIZE=20 +TOTAL_TRAIN_DATA_SIZE = 100 +TOTAL_LABEL_SIZE = 100 +TOTAL_VAL_DATA_SIZE = 20 FEATURE_SIZE = 3072 -def get_data_info(target): + +def get_data_info(): + """Return Data size + + Returns: + t_data_size, v_data_size, TOTAL_LABEL_SIZE, FEATURE_SIZE + """ t_data_size = TOTAL_TRAIN_DATA_SIZE v_data_size = TOTAL_VAL_DATA_SIZE return t_data_size, v_data_size, TOTAL_LABEL_SIZE, FEATURE_SIZE @@ -29,9 +34,19 @@ def get_data_info(target): ## # @brief load input data from file # @return (InputVector, InputLabel, Validation Vector, ValidationLabel) + + def load_data(target): + """Load data && save as file + + Args: + target (str): train || validation + + Returns: + input_vector, input_label, val_vector, val_label + """ # data_size = TOTAL_TRAIN_DATA_SIZE; - d_size = get_data_info(target) + d_size = get_data_info() if target == "validation": t_buf_size = d_size[0] @@ -40,33 +55,33 @@ def load_data(target): t_buf_size = d_size[0]*TOTAL_LABEL_SIZE v_buf_size = d_size[1]*TOTAL_LABEL_SIZE - InputVector = np.zeros((t_buf_size, FEATURE_SIZE),dtype=np.float32) - InputLabel = np.zeros((t_buf_size, TOTAL_LABEL_SIZE),dtype=np.float32) + input_vector = np.zeros((t_buf_size, FEATURE_SIZE), dtype=np.float32) + input_label = np.zeros((t_buf_size, TOTAL_LABEL_SIZE), dtype=np.float32) - ValVector = np.zeros((v_buf_size,FEATURE_SIZE),dtype=np.float32) - ValLabel = np.zeros((v_buf_size, TOTAL_LABEL_SIZE),dtype=np.float32) + val_vector = np.zeros((v_buf_size, FEATURE_SIZE), dtype=np.float32) + val_label = np.zeros((v_buf_size, TOTAL_LABEL_SIZE), dtype=np.float32) - #read Input & Label + # read Input & Label - fin = open('vgg_valSet.dat','rb') - for i in range(v_buf_size): - for j in range(FEATURE_SIZE): - data_str = fin.read(4) - ValVector[i,j] = struct.unpack('f',data_str)[0] - for j in range(TOTAL_LABEL_SIZE): - data_str = fin.read(4) - ValLabel[i,j] = struct.unpack('f',data_str)[0] - fin.close() + with open('vgg_valSet.dat', 'rb') as fin: + for i in range(v_buf_size): + for j in range(FEATURE_SIZE): + data_str = fin.read(4) + val_vector[i, j] = struct.unpack('f', data_str)[0] + for j in range(TOTAL_LABEL_SIZE): + data_str = fin.read(4) + val_label[i, j] = struct.unpack('f', data_str)[0] + fin.close() # we are using same training data for validation to check how internal implementation is working - fin=open('vgg_trainingSet.dat','rb') - for i in range(t_buf_size): - for j in range(FEATURE_SIZE): - data_str = fin.read(4) - InputVector[i,j] = struct.unpack('f',data_str)[0] - for j in range(TOTAL_LABEL_SIZE): - data_str = fin.read(4) - InputLabel[i,j] = struct.unpack('f',data_str)[0] - fin.close() - - return InputVector, InputLabel, ValVector, ValLabel + with open('vgg_trainingSet.dat', 'rb') as fin: + for i in range(t_buf_size): + for j in range(FEATURE_SIZE): + data_str = fin.read(4) + input_vector[i, j] = struct.unpack('f', data_str)[0] + for j in range(TOTAL_LABEL_SIZE): + data_str = fin.read(4) + input_label[i, j] = struct.unpack('f', data_str)[0] + fin.close() + + return input_vector, input_label, val_vector, val_label