def main(): args = doParsing() print(args) # Read training configuration (config file is in common for dataset creation and training hyperparameters) configParams = ConfigParams(args.configFile) # Select train device trainDevice = selectTrainDevice(args.useGpu) # Load DataProvider dataProvider = DatasetTFReader( datasetDir=args.datasetDir, datasetMetadata=DatasetMetadata().initFromJson(os.path.join(args.datasetDir, "metadata.json")), configParams=configParams) # Load base model graph (fine tuning training) baseTFModel = None try: baseTFModel = TensorflowModel(os.path.join(args.baseModelDir, "graph.pb")) except Exception as e: print("Warning: no base model provided or impossible to read," " this works only for custom model created from scratch") baseTFModel = TensorflowModel() # Append classifier for fine tuning training trainingModel = ModelFactory.create(config=configParams, tfmodel=baseTFModel, dataProvider=dataProvider, trainDevice=trainDevice) # Run training trainProcess = TrainProcess(config=configParams, trainingModel=trainingModel, dataProvider=dataProvider, outputDir=args.checkpointOutputDir, tensorboardDir=args.tensorboardDir) trainProcess.runTrain() # Freeze graph (graphdef plus parameters), # this includes in the graph only the layers needed to provide the output_node_names freeze_graph(input_graph=args.checkpointOutputDir + "/model_graph.pb", input_saver="", input_binary=True, input_checkpoint=args.checkpointOutputDir + "/model", output_node_names=configParams.outputName, restore_op_name="save/restore_all", filename_tensor_name="save/Const:0", output_graph=args.modelOutputDir + "/graph.pb", clear_devices=True, initializer_nodes="")
def create_product(): data = request.json factory = ModelFactory() product_id = factory.create(Product, seller=data['seller'], name=data['name']) for color in data['option']['color']: for size in data['option']['size']: factory.create(ProductOption, product_id=product_id, color=color, size=size) for seq, image in enumerate(data['images']): factory.create(ProductImage, product_id=product_id, seq=int(seq), path=image['path'], url=image['url']) factory.create(ProductPrice, product_id=product_id, price=data['price']) return jsonify(status=201, message='Created')