static int secure_gain_in(void) // form EFUSE { char buf[128]; char *pTemp = &(pin->factory_id[0]);; int ret; memset(buf, 0, 128); pTemp = &(pin->factory_id[0]); if(!get_in(buf, FROM_KERNEL)){ memcpy(pTemp, buf, CONFIG_EFUSE_IN_DATA_SIZE); pin->status = 0; ret = 0; } else{ memset(pTemp, 0, CONFIG_EFUSE_IN_DATA_SIZE); pin->status = -1; ret = -1; } return ret; }
void train_nn(struct net nwk, struct training t) { unsigned epoch = 0; unsigned freq = 500; unsigned limit = 5000; do { unsigned error = 0; for (size_t i = 0; i < t.n_set; ++i) { net_compute(nwk, get_in(&t, i)); net_error(nwk, get_out(&t, i)); if (epoch % freq == 0) { char c = convert_output(get_out(&t, i), 52); char rst = convert_output(net_output(nwk), 52); if (c != rst) { printf("In: %c\t", c); printf("Out: %c\n", rst); ++error; } } } if (epoch % freq == 0) { printf("[%d] ERROR: %d\n", epoch, error); printf("******************\n"); } ++epoch; if (epoch == limit) { printf("Continue? "); int b = 0; scanf("%d", &b); if (b) epoch = 0; } } while(epoch < limit); }
int main() { Tree p = NULL; int i = 0; gets(input); //puts(input); length = strlen(input); get_in(); get_num(); //get_in(len); /*for(i = 0; i < len; i++){ printf("%d\n", num[i]); }*/ p = (Tree)malloc(sizeof(Node)); build(0, len-1, p); /*printf("%d\n", p->data); printf("%d\n", p->lchild->data); printf("%d\n", p->rchild->data); printf("%d", p->lchild->lchild->data);*/ visit(p); return 0; }
struct training load_pattern(char *dir) { char path[2048]; char filename[2048]; t_img_desc *img; strcpy(path, dir); for (dir = path; *dir; ++dir); if (*(--dir) != '/') strcat(path, "/"); const size_t n_font = 7; const size_t n_letter = 52; const size_t n_set = n_letter * n_font; const size_t size_in = 400; const size_t size_out = 52; struct training t = { NULL, NULL, n_set, size_in, size_out }; t.in = malloc(sizeof(double) * t.n_in * t.n_set); assert(t.in); t.out = malloc(sizeof(double) * t.n_out * t.n_set); assert(t.out); for (size_t f = 0; f < n_font; ++f) { /* Lower */ for (size_t l = 0; l < n_letter / 2; ++l) { sprintf(filename, "%s%s/%c/%lu.png", path, "lower", (char)l+'A', f); img = load_image(filename, 1); printf("[INFO] Load %s (%ix%i -- %i)\n", filename, img->x, img->y, img->comp); process_pattern(img, 1); size_t line = l + f * n_letter; gen_input(img, get_in(&t, line)); gen_output(get_out(&t, line), size_out, (char)l+'a'); free_image(img); } /* Upper */ for (size_t l = 0; l < n_letter / 2; ++l) { sprintf(filename, "%s%s/%c/%lu.png", path, "upper", (char)l+'A', f); img = load_image(filename, 1); printf("[INFO] Load %s (%ix%i -- %i)\n", filename, img->x, img->y, img->comp); process_pattern(img, 1); size_t line = (l + 26) + f * n_letter; gen_input(img, get_in(&t, line)); gen_output(get_out(&t, line), size_out, (char)l+'A'); free_image(img); } } return t; }