Skip to content

Commit

Permalink
Release v1.0.0
Browse files Browse the repository at this point in the history
Release v1.0.0. First running version. The Mobilenet v1 used is not anymore
the `160x160x3` (alpha=`0.25`) - which does not fit on the SRAM - but the
`128x128x3` (alpha=`0.25`).

Changelog:

 ## Added
 - Keras Model import for the Mobilenet v1 `128x128x3` (alpha=`0.25`)
 - Keras Saved Models `.h5`
 - User-Space application template for Mobilenet Model (
 `Inc/usr_mobilenet.h`, `Src/usr_mobilenet.c`)

 ## Changed
 - Project STMCubeMX.AI updated to the new network
 - Added to the GPIO pin (`PB11`) for profiling the Mobilenet activity

 ## Fixed
 - Fixed Working Frequency of the MCU to 400MHz
  • Loading branch information
alessandrocapotondi committed Apr 3, 2019
1 parent 1adeb45 commit e4934de
Show file tree
Hide file tree
Showing 20 changed files with 189,789 additions and 191,220 deletions.
357 changes: 182 additions & 175 deletions .cproject

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Inc/app_x-cube-ai.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ typedef struct {
ai_i32 (*ai_forward)(ai_handle network, const ai_buffer* input);
} ai_network_entry_t;

#include "mobilenet.h"
#include "mobilenet_data.h"
#include "mobilenet_128_0_25.h"
#include "mobilenet_128_0_25_data.h"

#define AI_MNETWORK_NUMBER (1)
#define AI_MNETWORK_DATA_ACTIVATIONS_SIZE AI_MOBILENET_DATA_ACTIVATIONS_SIZE
#define AI_MNETWORK_IN_1_SIZE AI_MOBILENET_IN_1_SIZE
#define AI_MNETWORK_OUT_1_SIZE AI_MOBILENET_OUT_1_SIZE
#define AI_MNETWORK_DATA_ACTIVATIONS_SIZE AI_MOBILENET_128_0_25_DATA_ACTIVATIONS_SIZE
#define AI_MNETWORK_IN_1_SIZE AI_MOBILENET_128_0_25_IN_1_SIZE
#define AI_MNETWORK_OUT_1_SIZE AI_MOBILENET_128_0_25_OUT_1_SIZE

AI_API_DECLARE_BEGIN

Expand Down
10 changes: 6 additions & 4 deletions Inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,12 @@ void Error_Handler(void);
#define RMII_RXD0_GPIO_Port GPIOC
#define RMII_RXD1_Pin GPIO_PIN_5
#define RMII_RXD1_GPIO_Port GPIOC
#define Mobilenet_Pin GPIO_PIN_11
#define Mobilenet_GPIO_Port GPIOB
#define RMII_TXD1_Pin GPIO_PIN_13
#define RMII_TXD1_GPIO_Port GPIOB
#define LD3_Pin GPIO_PIN_14
#define LD3_GPIO_Port GPIOB
#define RedLED_Pin GPIO_PIN_14
#define RedLED_GPIO_Port GPIOB
#define STLK_RX_Pin GPIO_PIN_8
#define STLK_RX_GPIO_Port GPIOD
#define STLK_TX_Pin GPIO_PIN_9
Expand Down Expand Up @@ -106,8 +108,8 @@ void Error_Handler(void);
#define RMII_TXD0_GPIO_Port GPIOG
#define SWO_Pin GPIO_PIN_3
#define SWO_GPIO_Port GPIOB
#define LD2_Pin GPIO_PIN_7
#define LD2_GPIO_Port GPIOB
#define BlueLED_Pin GPIO_PIN_7
#define BlueLED_GPIO_Port GPIOB
/* USER CODE BEGIN Private defines */

/* USER CODE END Private defines */
Expand Down
2 changes: 1 addition & 1 deletion Inc/stm32h7xx_hal_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
* (when HSE is used as system clock source, directly or through the PLL).
*/
#if !defined (HSE_VALUE)
#define HSE_VALUE ((uint32_t)4000000) /*!< Value of the External oscillator in Hz : FPGA case fixed to 60MHZ */
#define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz : FPGA case fixed to 60MHZ */
#endif /* HSE_VALUE */

#if !defined (HSE_STARTUP_TIMEOUT)
Expand Down
88 changes: 88 additions & 0 deletions Inc/usr_mobilenet.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright (C) 2019 University of Bologna
*
* Author: Capotondi, Alessandro, University of Bologna
* <alessandro.capotondi@unibo.it>
*
* 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.
*/

#ifndef USR_MOBILENET_H_
#define USR_MOBILENET_H_

/******** Cycle counter defines **********/
#define MOBILENET_PROFILE 1

#if MOBILENET_PROFILE
extern volatile unsigned int *DWT_CYCCNT;
extern volatile unsigned int *DWT_CONTROL;
extern volatile unsigned int *SCB_DEMCR;
extern long long usr_nr_nb_run;
extern long long usr_cycle_counter;

#define USR_MEM_BARRIER() \
do { \
asm volatile("" ::: "memory");\
} while (0)

#define USR_CC_ENABLE() \
do { \
asm volatile("" ::: "memory"); \
*SCB_DEMCR = *SCB_DEMCR | 0x01000000;\
*DWT_CYCCNT = 0; \
*DWT_CONTROL = *DWT_CONTROL | 1; \
asm volatile("" ::: "memory"); \
} while (0)

#define USR_CC_RESET() \
do { \
asm volatile("" ::: "memory"); \
*DWT_CYCCNT = 0; \
asm volatile("" ::: "memory"); \
} while (0)

#define USR_GET_CC_TIMESTAMP_(x) \
do { \
asm volatile("" ::: "memory"); \
x = (*(volatile unsigned int *) DWT_CYCCNT); \
asm volatile("" ::: "memory"); \
} while (0)

#define USR_GET_CC_ACC_TIMESTAMP(acc) \
do { \
asm volatile("" ::: "memory"); \
acc += (*(volatile unsigned int *) DWT_CYCCNT); \
asm volatile("" ::: "memory"); \
} while (0)
#else
#define USR_MEM_BARRIER()
#define USR_CC_ENABLE()
#define USR_CC_RESET()
#define USR_GET_CC_TIMESTAMP(x)
#endif

/* Network Handle */
extern ai_handle mobilenet_network;

/* Global buffer to handle the activations data buffer - R/W data */
extern ai_u8 mobilenet_activations[];

/* Buffers to store the tensor input/output of the network */
extern ai_float in_data[];
extern ai_float out_data[];

int usr_mobilenet_init(void);
void usr_mobilenet_deinit(void);
int usr_mobilenet_run(const ai_float *in_data, ai_float *out_data);

#endif /* USR_MOBILENET_H_ */
373,878 changes: 186,939 additions & 186,939 deletions Middlewares/ST/AI/AI/data/mobilenet_data.c → ...s/ST/AI/AI/data/mobilenet_128_0_25_data.c

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
******************************************************************************
* @file mobilenet_data.h
* @file mobilenet_128_0_25_data.h
* @author AST Embedded Analytics Research Platform
* @date Tue Apr 2 10:27:45 2019
* @date Wed Apr 3 11:10:25 2019
* @brief AI Tool Automatic Code Generator for Embedded NN computing
******************************************************************************
* @attention
Expand All @@ -18,43 +18,43 @@
******************************************************************************
*/

#ifndef __MOBILENET_DATA_H_
#define __MOBILENET_DATA_H_
#ifndef __MOBILENET_128_0_25_DATA_H_
#define __MOBILENET_128_0_25_DATA_H_
#pragma once

#include "ai_platform.h"

#define AI_MOBILENET_DATA_CONFIG AI_HANDLE_NULL
#define AI_MOBILENET_128_0_25_DATA_CONFIG AI_HANDLE_NULL

#define AI_MOBILENET_DATA_ACTIVATIONS_SIZE (614404)
#define AI_MOBILENET_128_0_25_DATA_ACTIVATIONS_SIZE (393220)

#define AI_MOBILENET_DATA_WEIGHTS_SIZE (1869344)
#define AI_MOBILENET_128_0_25_DATA_WEIGHTS_SIZE (1869344)

#define AI_MOBILENET_DATA_ACTIVATIONS(ptr_) \
#define AI_MOBILENET_128_0_25_DATA_ACTIVATIONS(ptr_) \
AI_BUFFER_OBJ_INIT( \
AI_BUFFER_FORMAT_U8, \
1, 1, AI_MOBILENET_DATA_ACTIVATIONS_SIZE, 1, \
1, 1, AI_MOBILENET_128_0_25_DATA_ACTIVATIONS_SIZE, 1, \
AI_HANDLE_PTR(ptr_) )

#define AI_MOBILENET_DATA_WEIGHTS(ptr_) \
#define AI_MOBILENET_128_0_25_DATA_WEIGHTS(ptr_) \
AI_BUFFER_OBJ_INIT( \
AI_BUFFER_FORMAT_U8|AI_BUFFER_FMT_FLAG_CONST, \
1, 1, AI_MOBILENET_DATA_WEIGHTS_SIZE, 1, \
1, 1, AI_MOBILENET_128_0_25_DATA_WEIGHTS_SIZE, 1, \
AI_HANDLE_PTR(ptr_) )


AI_API_DECLARE_BEGIN

/*!
* @brief Get network weights array pointer as a handle ptr.
* @ingroup mobilenet_data
* @ingroup mobilenet_128_0_25_data
* @return a ai_handle pointer to the weights array
*/
AI_API_ENTRY
ai_handle ai_mobilenet_data_weights_get(void);
ai_handle ai_mobilenet_128_0_25_data_weights_get(void);


AI_API_DECLARE_END

#endif /* __MOBILENET_DATA_H_ */
#endif /* __MOBILENET_128_0_25_DATA_H_ */

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
******************************************************************************
* @file mobilenet.h
* @file mobilenet_128_0_25.h
* @author AST Embedded Analytics Research Platform
* @date Tue Apr 2 10:27:45 2019
* @date Wed Apr 3 11:10:25 2019
* @brief AI Tool Automatic Code Generator for Embedded NN computing
******************************************************************************
* @attention
Expand All @@ -18,31 +18,31 @@
******************************************************************************
*/

#ifndef __AI_MOBILENET_H__
#define __AI_MOBILENET_H__
#ifndef __AI_MOBILENET_128_0_25_H__
#define __AI_MOBILENET_128_0_25_H__
#pragma once

#include "ai_platform.h"

#define AI_MOBILENET_MODEL_NAME "mobilenet"
#define AI_MOBILENET_128_0_25_MODEL_NAME "mobilenet_128_0_25"

#define AI_MOBILENET_IN_NUM (1)
#define AI_MOBILENET_IN_1 \
AI_BUFFER_OBJ_INIT(AI_BUFFER_FORMAT_FLOAT, 160, 160, 3, 1, NULL)
#define AI_MOBILENET_IN_1_SIZE \
(160 * 160 * 3)
#define AI_MOBILENET_128_0_25_IN_NUM (1)
#define AI_MOBILENET_128_0_25_IN_1 \
AI_BUFFER_OBJ_INIT(AI_BUFFER_FORMAT_FLOAT, 128, 128, 3, 1, NULL)
#define AI_MOBILENET_128_0_25_IN_1_SIZE \
(128 * 128 * 3)

#define AI_MOBILENET_OUT_NUM (1)
#define AI_MOBILENET_OUT_1 \
#define AI_MOBILENET_128_0_25_OUT_NUM (1)
#define AI_MOBILENET_128_0_25_OUT_1 \
AI_BUFFER_OBJ_INIT(AI_BUFFER_FORMAT_FLOAT, 1, 1, 1000, 1, NULL)
#define AI_MOBILENET_OUT_1_SIZE \
#define AI_MOBILENET_128_0_25_OUT_1_SIZE \
(1 * 1 * 1000)


AI_API_DECLARE_BEGIN

/*!
* @defgroup mobilenet
* @defgroup mobilenet_128_0_25
* @brief Public neural network APIs
* @details This is the header for the network public APIs declarations
* for interfacing a generated network model.
Expand All @@ -61,18 +61,18 @@ AI_API_DECLARE_BEGIN

/*!
* @brief Get network library info as a datastruct.
* @ingroup mobilenet
* @ingroup mobilenet_128_0_25
* @param[out] report a pointer to the report struct where to
* store network info. See @ref ai_network_report struct for details
* @return a boolean reporting the exit status of the API
*/
AI_API_ENTRY
ai_bool ai_mobilenet_get_info(
ai_bool ai_mobilenet_128_0_25_get_info(
ai_handle network, ai_network_report* report);

/*!
* @brief Get first network error code.
* @ingroup mobilenet
* @ingroup mobilenet_128_0_25
* @details Get an error code related to the 1st error generated during
* network processing. The error code is structure containing an
* error type indicating the type of error with an associated error code
Expand All @@ -82,75 +82,75 @@ ai_bool ai_mobilenet_get_info(
* see @ref ai_error for struct definition
*/
AI_API_ENTRY
ai_error ai_mobilenet_get_error(ai_handle network);
ai_error ai_mobilenet_128_0_25_get_error(ai_handle network);

/*!
* @brief Create a neural network.
* @ingroup mobilenet
* @ingroup mobilenet_128_0_25
* @details Instantiate a network and returns an object to handle it;
* @param network an opaque handle to the network context
* @param network_config a pointer to the network configuration info coded as a
* buffer
* @return an error code reporting the status of the API on exit
*/
AI_API_ENTRY
ai_error ai_mobilenet_create(
ai_error ai_mobilenet_128_0_25_create(
ai_handle* network, const ai_buffer* network_config);

/*!
* @brief Destroy a neural network and frees the allocated memory.
* @ingroup mobilenet
* @ingroup mobilenet_128_0_25
* @details Destroys the network and frees its memory. The network handle is returned;
* if the handle is not NULL, the unloading has not been successful.
* @param network an opaque handle to the network context
* @return an object handle : AI_HANDLE_NULL if network was destroyed
* correctly. The same input network handle if destroy failed.
*/
AI_API_ENTRY
ai_handle ai_mobilenet_destroy(ai_handle network);
ai_handle ai_mobilenet_128_0_25_destroy(ai_handle network);

/*!
* @brief Initialize the data structures of the network.
* @ingroup mobilenet
* @ingroup mobilenet_128_0_25
* @details This API initialized the network after a successfull
* @ref ai_mobilenet_create. Both the activations memory buffer
* @ref ai_mobilenet_128_0_25_create. Both the activations memory buffer
* and params (i.e. weights) need to be provided by caller application
*
* @param network an opaque handle to the network context
* @param params the parameters of the network (required).
* see @ref ai_network_params struct for details
* @return true if the network was correctly initialized, false otherwise
* in case of error the error type could be queried by
* using @ref ai_mobilenet_get_error
* using @ref ai_mobilenet_128_0_25_get_error
*/
AI_API_ENTRY
ai_bool ai_mobilenet_init(
ai_bool ai_mobilenet_128_0_25_init(
ai_handle network, const ai_network_params* params);


/*!
* @brief Run the network and return the output
* @ingroup mobilenet
* @ingroup mobilenet_128_0_25
*
* @details Runs the network on the inputs and returns the corresponding output.
* The size of the input and output buffers is stored in this
* header generated by the code generation tool. See AI_MOBILENET_*
* defines into file @ref mobilenet.h for all network sizes defines
* header generated by the code generation tool. See AI_MOBILENET_128_0_25_*
* defines into file @ref mobilenet_128_0_25.h for all network sizes defines
*
* @param network an opaque handle to the network context
* @param[in] input buffer with the input data
* @param[out] output buffer with the output data
* @return the number of input batches processed (default 1) or <= 0 if it fails
* in case of error the error type could be queried by
* using @ref ai_mobilenet_get_error
* using @ref ai_mobilenet_128_0_25_get_error
*/
AI_API_ENTRY
ai_i32 ai_mobilenet_run(
ai_i32 ai_mobilenet_128_0_25_run(
ai_handle network, const ai_buffer* input, ai_buffer* output);

/*!
* @brief Runs the network on the inputs.
* @ingroup mobilenet
* @ingroup mobilenet_128_0_25
*
* @details Differently from @ref ai_network_run, no output is returned, e.g. for
* temporal models with a fixed step size.
Expand All @@ -159,13 +159,13 @@ ai_i32 ai_mobilenet_run(
* @param[in] input buffer with the input data
* @return the number of input batches processed (usually 1) or <= 0 if it fails
* in case of error the error type could be queried by
* using @ref ai_mobilenet_get_error
* using @ref ai_mobilenet_128_0_25_get_error
*/
AI_API_ENTRY
ai_i32 ai_mobilenet_forward(
ai_i32 ai_mobilenet_128_0_25_forward(
ai_handle network, const ai_buffer* input);


AI_API_DECLARE_END

#endif /*__AI_MOBILENET_H__*/
#endif /*__AI_MOBILENET_128_0_25_H__*/
Loading

0 comments on commit e4934de

Please sign in to comment.